<!DOCTYPE HTML>


<html>
<head>
	<title>Home Made Java Virtual Machine - CodeProject</title> 
	<link type="text/css" rel="stylesheet" href="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Css/Main.css?dt=2.8.150129.1">

	
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Description" content="Functional java virtual machine - can run java applications for most of the instructions.; Author: Maruf Maniruzzaman; Updated: 17 Mar 2008; Section: C / C++ Language; Chapter: Languages; Updated: 17 Mar 2008" />
<meta name="Keywords" content="VC6, VC7, VC7.1, VC8.0, C++, C++/CLI, C, Java SE, Virtualization, virtual-machine,C / C++ Language,Languages,Free source code, tutorials" />
<meta name="Author" content="Maruf Maniruzzaman" />
<meta name="Rating" content="General" />
<meta name="Robots" content="index, follow, NOODP" />
<meta name="Revisit-After" content="1 days" />
<meta name="application-name" content="CodeProject" />
<meta name="google-translate-customization" content="d908bb7ce7aff658-4c2f3a504525c916-g629383f736781a8a-13" />

<link rel="dns-prefetch" href="//ajax.googleapis.com" /> 
<link rel="canonical" href="/Articles/24029/Home-Made-Java-Virtual-Machine" />


<link rel="alternate" type="application/rss+xml" title="CodeProject Latest articles - All Topics" href="http://www.codeproject.com/WebServices/ArticleRSS.aspx?cat=1" />
<link rel="alternate" type="application/rss+xml" title="CodeProject Latest articles - Android" href="http://www.codeproject.com/WebServices/ArticleRSS.aspx?cat=22" />
<link rel="alternate" type="application/rss+xml" title="CodeProject Latest articles - iOS" href="http://www.codeproject.com/WebServices/ArticleRSS.aspx?cat=25" />
<link rel="alternate" type="application/rss+xml" title="CodeProject Latest articles - C++" href="http://www.codeproject.com/WebServices/ArticleRSS.aspx?cat=2" />
<link rel="alternate" type="application/rss+xml" title="CodeProject Latest articles - C#" href="http://www.codeproject.com/WebServices/ArticleRSS.aspx?cat=3" />
<link rel="alternate" type="application/rss+xml" title="CodeProject Latest articles - Web" href="http://www.codeproject.com/WebServices/ArticleRSS.aspx?cat=23" />
<link rel="alternate" type="application/rss+xml" title="CodeProject Lounge Postings" href="http://www.codeproject.com/webservices/LoungeRSS.aspx" />
<link rel="search" type="application/opensearchdescription+xml" title="CodeProject" href="http://www.codeproject.com/info/OpenSearch.xml" />

	<base target="_top" />
	<link rel="icon" href="/favicon.ico" type="image/ico" >
<link rel="shortcut icon" href="/favicon.ico"  type="image/ico" >
<link rel="apple-touch-icon" href="/images/FavIcon-Apple.png" type="image/png" >
<script type="text/javascript" language="Javascript">//<![CDATA[
function defrm () { /* thanks twitter */ document.write = ''; window.top.location = window.self.location;  setTimeout(function() { document.body.innerHTML = ''; }, 0);  window.self.onload = function(evt) { document.body.innerHTML = ''; }; }if (window.top !== window.self) {  try {  if (window.top.location.host) { /* will throw */ } else { defrm(); /* chrome */ }  } catch (ex) { defrm(); /* everyone else */ } }if (typeof(DemoUrl)!='undefined')   document.write(unescape('%3Cme')+'ta http'+'-equiv="re'+'fresh"                  con'+'tent="1;url='+DemoUrl+unescape('"%3CE'));
function _dmBootstrap(file) { var _dma = document.createElement('script');  _dma.type = 'text/javascript'; _dma.async = true;  _dma.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + file; (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(_dma);}
function _dmFollowup(file) { if (typeof DMAds === 'undefined')  _dmBootstrap('cdn1.developermedia.com/a.min.js?dt=2.8.150129.1');}
(function () { _dmBootstrap('cdn1.developermedia.com/a.min.js?dt=2.8.150129.1'); setTimeout(_dmFollowup, 2000);})();

//]]>
</script>

	




<script type="text/javascript">
	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', 'UA-1735123-1']);
	_gaq.push(['_trackPageview']);
	_gaq.push(['_setDomainName', 'www.codeproject.com']);
	_gaq.push(['_setSessionTimeout', '1200']); 

	(function () {
		var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
		(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(ga);
	})(); 
</script>


</head>	

<body class="chrome chrome39">

<a class="access-link" href="#Main"><img alt="Click here to Skip to main content" src="//dj9okeyxktdvd.cloudfront.net/Images/t.gif" /></a>





<div class="page-background">

	
	

	

	<table id="ctl00_Bn" style="width:100%;height:135px" cellpadding="0" cellspacing="0" class="banner fixed">
	<tr valign="bottom">
		<td class="blank-background" style="height:31px">&nbsp;</td>
		<td class="blank-background" rowspan="3" style="width:250px;height:135px"><a href="/"><img id="ctl00_Logo" tabindex="1" title="CodeProject" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/logo250x135.gif" alt="Home" style="height:135px;width:250px;border-width:0px;" /></a></td>
		<td class="blank-background align-right" style="width:728px;height:31px">

<div class="container memberbar clearfix">

	<div id="ctl00_MemberMenu_GenInfo" class="float-left">11,187,337 members (69,912 online)</div>

	<div class="float-left">
		
	</div>

	<div class="float-right">

		

		

		

			<script type="text/javascript">//<!--
			function doSubmit(secure)
			{
				if (secure)
					document.subForm.action = "https://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine"
				else
					document.subForm.action = "https://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine"
				document.subForm.submit();
				return true;
			}//-->
			</script>

			<a name="SignUp"></a>
			<span class="member-signin tooltip openable">
				<span><a href="https://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign in</a></span>

				<div class="tooltip-flyout">
					<form name="subForm" id="subForm" action="https://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine" method="post" 
						class="tight">

						
						<input id="FormName" name="FormName" value="MenuBarForm" type="hidden" />

						<div>Email</div>
						<div><input class="small-text" type="email" name="Email" id="Email" /></div>
						<div>Password</div>
						<div><input class="small-text" type="password" name="Password" id="Password" /></div>
						<div class="action">
							
<script type="text/javascript">
function Join(){
 var url = 'http://www.codeproject.com/script/Membership/Modify.aspx?meml=' + document.subForm.Email.value;
 document.location.href=url;return false;
}
document.write('<input type="button" class="create" onclick="return Join();" value="Join"');
document.write('<input type="hidden" name="fld_quicksign" value="true" />');
</script>
							<input type="submit" value="Sign in" class="signin" 
								onclick="return doSubmit(false);" />
						</div>

						<div class="container">
							
							&nbsp;
							<a id="ctl00_MemberMenu_SendPassword" class="forgot float-right" href="/script/Membership/SendPassword.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Forgot your password?</a>
						</div>
					</form>

					<hr class="divider-dark" />

					Sign in using <a class="oauth" title="Sign in using Facebook" href="/script/Membership/OAuthLogOn.aspx?auth=Facebook"><img src="/script/Membership/Images/facebook.png" style="vertical-align:middle;padding-right:3px;border:0;" /></a>
<a class="oauth" title="Sign in using Google" href="/script/Membership/OAuthLogOn.aspx?auth=Google"><img src="/script/Membership/Images/google-plus.png" style="vertical-align:middle;padding-right:3px;border:0;" /></a>
<a class="oauth" title="Sign in using Linkedin" href="/script/Membership/OAuthLogOn.aspx?auth=LinkedIn"><img src="/script/Membership/Images/linkedin.png" style="vertical-align:middle;padding-right:3px;border:0;" /></a>
<a class="oauth" title="Sign in using Microsoft" href="/script/Membership/OAuthLogOn.aspx?auth=Microsoft"><img src="/script/Membership/Images/microsoft.png" style="vertical-align:middle;padding-right:3px;border:0;" /></a>

				</div>
            </span>
		
	</div>
</div></td>
		<td class="blank-background" style="height:31px">&nbsp;</td>
	</tr>
	<tr valign="middle">
		<td class="theme1-background" style="height:94px">&nbsp;</td>
		<td class="theme1-background ad"><div class="msg-728x90" data-format="728x90" data-type="ad" data-publisher="lqm.codeproject.site" data-zone="Languages/C-Cplusplus-Language/General"  data-tags='VC6, VC7, VC7.1, VC8.0, C++, C++/CLI, C, Java SE, Virtualization, virtual-machine,rating4.5'><noscript><a href="http://ad.doubleclick.net/N6839/jump/lqm.codeproject.site/Languages/C-Cplusplus-Language/General;sz=728x90;ord=635581648380709040?"><img src="http://ad.doubleclick.net/N6839/ad/lqm.codeproject.site/Languages/C-Cplusplus-Language/General;sz=728x90;ord=635581648380709040?"  width="728px" height="90px" /></a></noscript></div></td>
		<td class="theme1-background" style="height:94px">&nbsp;</td>
	</tr>
	<tr valign="top">
		<td style="height: 14px;"></td>
		<td style="height: 14px;" class="blank-background"></td>
		<td style="height: 14px;"></td>
	</tr>
</table>


	<a href="#Main"><img alt="Click here to Skip to main content" class="access-link" 
        src="//dj9okeyxktdvd.cloudfront.net/Images/t.gif" /></a>

	
	<div id="ctl00_TPR" class="sub-headerbar fixed">
	<table cellpadding="0" cellspacing="0" class="extended"><tr><td nowrap="nowrap">
		

<div class="navbar clearfix">
<ul class="navmenu openable">

<li><a id="ctl00_TopNavBar_Home" href="http://www.codeproject.com">home</a>


<li class="openable"><a id="ctl00_TopNavBar_Art" class="down selected" href="/script/Articles/Latest.aspx">articles</a>

	<ul>
		<li class="openable"><a id="ctl00_TopNavBar_ArtTopicList" class="fly" onmouseover="navBarMenu.ShowMap(this, &#39;ctl00_TopNavBar_MapFlyout&#39;);" href="/script/Content/SiteMap.aspx">Chapters and Sections<span class="has-submenu">&gt;</span></a><ul id="ctl00_TopNavBar_MapFlyout">
			<li>
				<div id="siteMap">
					<img src="//dj9okeyxktdvd.cloudfront.net/images/animated.gif" alt="loading" style="margin:150px;width:100px;height:100px;" />
				</div>
			</li>
			</ul>
		</li>
		<li><a id="ctl00_TopNavBar_ArtSearch" class="fly break" href="/search.aspx?sbo=kw">Search</a></li>
		<li><a id="ctl00_TopNavBar_ArtLatestArts" class="fly" href="/script/Articles/Latest.aspx?at=1,3,7">Latest Articles</a></li>
		<li><a id="ctl00_TopNavBar_ArtLatestTips" class="fly" href="/script/Articles/Latest.aspx?at=6">Latest Tips/Tricks</a></li>
		<li><a id="ctl00_TopNavBar_ArtTop" class="fly" href="/script/Articles/TopArticles.aspx?ta_so=5">Top Articles</a></li>
		<li><a id="ctl00_TopNavBar_ArtBeginner" class="fly" href="/search.aspx?sbo=kw?aidlst=152&amp;sa_us=True">Beginner Articles</a></li>
		<li><a id="ctl00_TopNavBar_ArtBlogArticles" class="fly break" href="/script/Articles/BlogArticleList.aspx">Technical Blogs</a></li>
		<li><a id="ctl00_TopNavBar_ArtGuide" class="fly" href="/info/Submit.aspx">Posting/Update Guidelines</a></li>
		<li><a id="ctl00_TopNavBar_ArtHelpForum" class="fly" href="/Forums/1641/Article-Writing.aspx">Article Help Forum</a></li>
		<li><a id="ctl00_TopNavBar_ArtCompetition" class="fly break" href="/script/Awards/CurrentCompetitions.aspx?cmpTpId=1">Article Competition</a></li>
		<li><a id="ctl00_TopNavBar_ArtPostArticle" class="fly highlight1" href="/script/Articles/Submit.aspx">
			<img src="//dj9okeyxktdvd.cloudfront.net/images/write13.png" width="13px" height="13px" /> Submit an article or tip
			</a></li>
		<li><a id="ctl00_TopNavBar_ArtPostBlog" class="fly highlight2" href="/script/Articles/BlogFeed.aspx">
			<img src="//dj9okeyxktdvd.cloudfront.net/images/write13.png" width="13px" height="13px" /> Post your Blog
			</a></li>		<li class="last"></li>
	</ul>

</li>



<li class="openable"><a id="ctl00_TopNavBar_Answers" href="/script/Answers/List.aspx?tab=active">quick answers</a>
	<ul>
		<li id="ctl00_TopNavBar_AQL"><a id="ctl00_TopNavBar_ArticleQuestion" class="fly highlight1" href="#_comments">
			<img src="//dj9okeyxktdvd.cloudfront.net/images/write13.png" width="13px" height="13px" /> Ask a Question about this 
			article</a>
		</li>

		<li><a id="ctl00_TopNavBar_QAAsk" class="fly highlight2" href="/Questions/ask.aspx"><img 
			src="//dj9okeyxktdvd.cloudfront.net/images/write13.png" width="13px" height="13px" /> Ask a Question</a></li>

		
		<li><a id="ctl00_TopNavBar_QAUnanswered" class="fly" href="/script/Answers/List.aspx?tab=unanswered">View Unanswered Questions</a></li>
		<li><a id="ctl00_TopNavBar_QALatest" class="fly" href="/script/Answers/List.aspx?tab=active">View All Questions...</a></li>
		
				<li><a id="ctl00_TopNavBar_QATR_ctl00_Tag" class="fly" href="/script/Answers/List.aspx?tab=active&amp;alltags=true&amp;tags=81" style="padding-left:30px">C# questions</a></li>
			
				<li><a id="ctl00_TopNavBar_QATR_ctl01_Tag" class="fly" href="/script/Answers/List.aspx?tab=active&amp;alltags=true&amp;tags=85" style="padding-left:30px">ASP.NET questions</a></li>
			
				<li><a id="ctl00_TopNavBar_QATR_ctl02_Tag" class="fly" href="/script/Answers/List.aspx?tab=active&amp;alltags=true&amp;tags=842" style="padding-left:30px">VB.NET questions</a></li>
			
				<li><a id="ctl00_TopNavBar_QATR_ctl03_Tag" class="fly" href="/script/Answers/List.aspx?tab=active&amp;alltags=true&amp;tags=93" style="padding-left:30px">SQL questions</a></li>
			
				<li><a id="ctl00_TopNavBar_QATR_ctl04_Tag" class="fly" href="/script/Answers/List.aspx?tab=active&amp;alltags=true&amp;tags=87" style="padding-left:30px">Javascript questions</a></li>
			
		<li class="last"></li>
	</ul>

</li>



<li class="openable"><a id="ctl00_TopNavBar_Forums" href="/script/Forums/List.aspx">discussions</a>

	<ul>
		<li><a id="ctl00_TopNavBar_MessageBoardsAll" class="fly" href="/script/Forums/List.aspx">All Message Boards...</a></li>
		<li class="openable"><a class="fly" style="padding-left:30px" href="/Forums/1580997/Application-Lifecycle.aspx">Application Lifecycle<span class="has-submenu">&gt;</span></a>
<ul class="openable"><li><a class="fly" href="/Forums/1533717/Running-a-Business.aspx">Running a Business</a></li>
<li><a class="fly" href="/Forums/1533716/Sales-Marketing.aspx">Sales / Marketing</a></li>
<li><a class="fly" href="/Forums/1651/Collaboration-Beta-Testing.aspx">Collaboration / Beta Testing</a></li>
<li><a class="fly" href="/Forums/3304/Work-Training-Issues.aspx">Work &amp; Training Issues</a></li>
</ul></li>
<li><a class="fly" style="padding-left:30px" href="/Forums/369270/Design-and-Architecture.aspx">Design and Architecture</a>
</li>
<li><a class="fly" style="padding-left:30px" href="/Forums/12076/ASP-NET.aspx">ASP.NET</a>
</li>
<li><a class="fly" style="padding-left:30px" href="/Forums/1580226/JavaScript.aspx">JavaScript</a>
</li>
<li class="openable"><a class="fly" style="padding-left:30px" href="/Forums/1647/C-Cplusplus-MFC.aspx">C / C++ / MFC<span class="has-submenu">&gt;</span></a>
<ul class="openable"><li><a class="fly" href="/Forums/4486/ATL-WTL-STL.aspx">ATL /  WTL / STL</a></li>
<li><a class="fly" href="/Forums/3785/Managed-Cplusplus-CLI.aspx">Managed C++/CLI</a></li>
</ul></li>
<li><a class="fly" style="padding-left:30px" href="/Forums/1827459/Adobe-Technologies.aspx">Adobe Technologies</a>
</li>
<li><a class="fly" style="padding-left:30px" href="/Forums/1649/Csharp.aspx">C#</a>
</li>
<li><a class="fly" style="padding-left:30px" href="/Forums/1627782/Free-Tools.aspx">Free Tools</a>
</li>
<li><a class="fly" style="padding-left:30px" href="/Forums/1827460/Objective-C.aspx">Objective-C</a>
</li>
<li><a class="fly" style="padding-left:30px" href="/Forums/1832431/Ruby-On-Rails.aspx">Ruby On Rails</a>
</li>
<li><a class="fly" style="padding-left:30px" href="/Forums/1725/Database.aspx">Database</a>
</li>
<li class="openable"><a class="fly" style="padding-left:30px" href="/Forums/186301/Hardware-Devices.aspx">Hardware &amp; Devices<span class="has-submenu">&gt;</span></a>
<ul class="openable"><li><a class="fly" href="/Forums/1644/System-Admin.aspx">System Admin</a></li>
</ul></li>
<li><a class="fly" style="padding-left:30px" href="/Forums/1606152/Hosting-and-Servers.aspx">Hosting and Servers</a>
</li>
<li><a class="fly" style="padding-left:30px" href="/Forums/1643/Java.aspx">Java</a>
</li>
<li><a class="fly" style="padding-left:30px" href="/Forums/1650/NET-Framework.aspx">.NET Framework</a>
</li>
<li><a class="fly" style="padding-left:30px" href="/Forums/1848626/Android.aspx">Android</a>
</li>
<li><a class="fly" style="padding-left:30px" href="/Forums/1876716/iOS.aspx">iOS</a>
</li>
<li><a class="fly" style="padding-left:30px" href="/Forums/13695/Mobile.aspx">Mobile</a>
</li>
<li><a class="fly" style="padding-left:30px" href="/Forums/1540733/Sharepoint.aspx">Sharepoint</a>
</li>
<li><a class="fly" style="padding-left:30px" href="/Forums/1004257/Silverlight-WPF.aspx">Silverlight / WPF</a>
</li>
<li><a class="fly" style="padding-left:30px" href="/Forums/1646/Visual-Basic.aspx">Visual Basic</a>
</li>
<li><a class="fly" style="padding-left:30px" href="/Forums/1640/Web-Development.aspx">Web Development</a>
</li>
<li><a class="fly" style="padding-left:30px" href="/suggestions.aspx">Site Bugs / Suggestions</a>
</li>

		<li class="last"></li>
	</ul>

</li>

<li class="openable"><a id="ctl00_TopNavBar_Features" href="/Feature/">features</a>

	<ul>
		<li><a id="ctl00_TopNavBar_Comps" class="fly" href="/script/Awards/CurrentCompetitions.aspx?cmpTpId=1&amp;awsac=true">Competitions</a></li>
		<li><a id="ctl00_TopNavBar_News" class="fly" href="/script/News/List.aspx">News</a></li>
		<li><a id="ctl00_TopNavBar_Insider" class="fly" href="/Feature/Insider/">The Insider Newsletter</a></li>
    	<li><a id="ctl00_TopNavBar_DailyBuild" class="fly" href="/Feature/DailyBuild">The Daily Build Newsletter</a></li>
		<li><a id="ctl00_TopNavBar_Newsletters" class="fly" href="/script/Mailouts/Archive.aspx?mtpid=1">Newsletter archive</a></li>
		<li><a id="ctl00_TopNavBar_Surveys" class="fly" href="/script/Surveys/List.aspx">Surveys</a></li>
		<li><a id="ctl00_TopNavBar_Showcase" class="fly" href="/KB/showcase/">Product Showcase</a></li>
		<li><a id="ctl00_TopNavBar_Research" class="fly" href="/script/ResearchLibrary/Index.aspx">Research Library</a></li>

		<li><a id="ctl00_TopNavBar_Stuff" class="fly" href="/Info/Stuff.aspx">CodeProject Stuff</a></li>
		<li class="last"></li>
	</ul>

</li>


<li  class="openable"><a id="ctl00_TopNavBar_Lounge" href="/Lounge.aspx">community</a>

	<ul>
		<li><a id="ctl00_TopNavBar_WhosWho" class="fly" href="/script/Membership/Profiles.aspx">Who's Who</a></li>
		<li><a id="ctl00_TopNavBar_MVPs" class="fly break" href="/script/Awards/MVPWinners.aspx">Most Valuable Professionals</a></li>
		

		<li><a id="ctl00_TopNavBar_LoungeLnk" class="fly highlight2" href="/Lounge.aspx">The Lounge  </a></li>
		<li><a id="ctl00_TopNavBar_InsiderLnk" class="fly" href="/Insider.aspx">The Insider News</a></li>
		<li><a id="ctl00_TopNavBar_WeirdWonderful" class="fly" href="/Feature/WeirdAndWonderful.aspx">The Weird & The Wonderful</a></li>
		<li><a id="ctl00_TopNavBar_SoapBoxLnk" class="fly" href="/Forums/1536756/The-Soapbox.aspx">The Soapbox</a></li>
		<li><a id="ctl00_TopNavBar_PRLnk" class="fly break" href="/Forums/1738007/Press-Releases.aspx">Press Releases</a></li>

		
		<li class="openable"><a class="fly" href="/Forums/1580229/Hindi.aspx">Non-English Language
			<span class="has-submenu">&gt;</span></a>
		<ul>
		<li><a class="fly" href="/Forums/1580229/Hindi.aspx">General Indian Topics</a></li>
		<li><a class="fly" href="/Forums/1580230/Chinese.aspx">General Chinese Topics</a></li>
		</ul>
		<li class="last"></li>
		
	</ul>

</li>


<li class="openable" style="margin-left:20px"><a id="ctl00_TopNavBar_Help" href="/KB/FAQs/">help</a>

	<ul>
		<li><a id="ctl00_TopNavBar_HelpWhatIs" class="fly" href="/info/guide.aspx">What is 'CodeProject'?</a></li>
		<li><a id="ctl00_TopNavBar_HelpGeneral" class="fly break" href="/KB/FAQs/">General FAQ</a></li>
		<li><a id="ctl00_TopNavBar_HelpPostQuestion" class="fly break highlight2" href="/Questions/ask.aspx">Ask a Question</a></li>
		<li><a id="ctl00_TopNavBar_HelpBugs" class="fly" href="/suggestions.aspx">Bugs and Suggestions</a></li>
		<li><a id="ctl00_TopNavBar_HelpArticles" class="fly" href="/Forums/1641/Article-Writing.aspx">Article Help Forum</a></li>
		<li><a id="ctl00_TopNavBar_HelpSiteMap" class="fly" href="/script/Content/SiteMap.aspx">Site Map</a></li>
		<li><a id="ctl00_TopNavBar_HelpAdvertise" class="fly" href="http://developermedia.com/">Advertise with us</a></li>
		<li><a id="ctl00_TopNavBar_HelpJobs" class="fly" href="/info/Jobs/">Employment Opportunities</a></li>
		<li><a id="ctl00_TopNavBar_HelpAboutUs" class="fly" href="/info/about.aspx">About Us</a></li>
		<li class="last"></li>
	</ul>

</li>

</ul>

</div>
	</td><td align="right">
		

<div class="searchbar">

<form method="get" action="/search.aspx?sbo=kw" name="Search" class="tight">


<table border="0" cellspacing="0" cellpadding="0" class="search"><tr><td><input TabIndex="2" class="search " id="sb_tb" value="" name="q" /></td><td><input type="image" src="//dj9okeyxktdvd.cloudfront.net/images/search.gif" /></td></tr></table>

<div class="hover-container">
	<div id="SearchFilter" class="search-advanced popup small-text align-left">
	<b>Search within:<br /></b>
		
		<input type="radio" id="sb_kw" name="sbo" value="kw" checked="true"><label for="sb_kw">Articles</label><br>
<input type="radio" id="sb_qa" name="sbo" value="qa"><label for="sb_qa">Quick Answers</label><br>
<input type="radio" id="sb_fm" name="sbo" value="fm"><label for="sb_fm">Messages</label><br>


		
		

		
		
	</div>
</div>
</form>

</div>
	</td></tr></table>
	<div class="sub-headerbar-divider"></div>
	</div>
	

	<div id="A" class="container-content-wrap fixed"> 

	<div itemscope itemtype="http://schema.org/Article" class="container-content"> 

		<div class="clearfix">
			<div class="float-left container-breadcrumb">
				<div><a href="/script/Content/SiteMap.aspx">Articles</a> &#187; <a href="/Chapters/5/Languages.aspx">Languages</a> &#187; <a href="/KB/cpp/"><span itemprop="articleSection">C / C++ Language</span></a> &#187; <a href="/KB/cpp/#General">General</a></div>
			</div>

			<div class="align-left float-right padded-top" style="width">
				


 
&nbsp;










			</div>

			<div class="float-right article-nav">
				
				

<a id="ctl00_ActionLinks_BookmarkMd_ImgBt" title="Bookmark" AlternateText="Bookmark" name="bm_24029_2" onclick="return bookmarkMe(24029,2,&#39;/script/Bookmarks/Ajax/Add.aspx?obid=24029&amp;obtid=2&amp;action=AddBookmark&amp;bio=true&amp;bis=medium&#39;,&#39;medium&#39;);" href="/script/Bookmarks/Add.aspx?obid=24029&amp;obtid=2&amp;action=AddBookmark&amp;bio=true&amp;bis=medium" style="display:inline-block;height:24px;width:24px;"><img title="Bookmark" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/bookmark24.png" alt="" style="border-width:0px;" /></a>


<span id="ctl00_ActionLinks_BookmarkMd_StatusMsg" class="tiny-text" style="display:none" name="bm_24029_2"></span>
<a id="ctl00_ActionLinks_PrintMd" href="/Articles/24029/Home-Made-Java-Virtual-Machine?display=Print">
	<img src="//dj9okeyxktdvd.cloudfront.net/images/print24.png" title="Print"
		width="24px" height="24px" style="border:0">
</a>
			</div>

			<div class="align-right float-left">
				
			</div>
		</div>

		<table class="extended container-article-parts" cellpadding="0" cellspacing="0">
        <tr valign="top">
		<td width="117px">

			<div id="ctl00_Nav" class="container-article-tabs">
				<div class="tabs">
					

<div class="">
	<div class="selected">Article</div><div class="unselected"><a href="/script/Articles/ViewDownloads.aspx?aid=24029">Browse Code</a></div><div class="unselected"><a href="/script/Articles/Statistics.aspx?aid=24029">Stats</a></div><div class="unselected"><a href="/script/Articles/ListVersions.aspx?aid=24029">Revisions</a></div><div class="unselected"><a href="/script/Articles/ListAlternatives.aspx?aid=24029">Alternatives</a></div>

	<div class="unselected"><a href="WebControls/#_comments" id="ctl00_ArticleTabs_CommentLink" class="anchorLink">Comments 
        <span id="ctl00_ArticleTabs_CmtCnt">(28)</span></a>
	</div>
</div>	

				</div>

				

			    <div class="tags"> 
                    <h4>Tagged as</h4>
			        <span id="ctl00_TagsList_TagWrp" class="tags">
	
	
	
	<span id="ctl00_TagsList_VisibleTags"><div class="t"><a rel="tag" href="/Tags/VC6">VC6</a></div><div class="t"><a rel="tag" href="/Tags/VC7">VC7</a></div><div class="t"><a rel="tag" href="/Tags/VC7.1">VC7.1</a></div><div class="t"><a rel="tag" href="/Tags/VC8.0">VC8.0</a></div><div class="t"><a rel="tag" href="/Tags/C--plus----plus--">C++</a></div><div class="t"><a rel="tag" href="/Tags/C--plus----plus----slash--CLI">C++/CLI</a></div><div class="t"><a rel="tag" href="/Tags/C">C</a></div><div class="t"><a rel="tag" href="/Tags/Java+SE">Java SE</a></div><div class="t"><a rel="tag" href="/Tags/Virtualization">Virtualization</a></div><div class="t"><a rel="tag" href="/Tags/virtual-machine">virtual-machine</a></div></span> 

	
	
</span>

			    </div>

				<div class="padded-top related">
					
	<h4 id="ctl00_RelatedArticles_RelatedResults_ctl00_header">Related Articles</h4>
	<div class="content-list">	
	
	<div class="content-list-item">
		<a id="ctl00_RelatedArticles_RelatedResults_ctl01_Link" href="/Articles/43176/How-to-create-your-own-virtual-machine">How to create your own virtual machine</a>
		
	</div>
	
	<div class="content-list-item">
		<a id="ctl00_RelatedArticles_RelatedResults_ctl03_Link" href="/Articles/1825/The-Common-Language-Runtime-CLR-and-Java-Runtime-E">The Common Language Runtime (CLR) and Java Runtime Environment (JRE)</a>
		
	</div>
	
	<div class="content-list-item">
		<a id="ctl00_RelatedArticles_RelatedResults_ctl04_Link" href="/Articles/803458/Setting-Up-Your-Android-Development-Environment">Setting Up Your Android Development Environment</a>
		
	</div>
	
	<div class="content-list-item">
		<a id="ctl00_RelatedArticles_RelatedResults_ctl05_Link" href="/Articles/36907/How-to-develop-your-own-Boot-Loader">How to develop your own Boot Loader</a>
		
	</div>
	
	<div class="content-list-item">
		<a id="ctl00_RelatedArticles_RelatedResults_ctl06_Link" href="/Articles/44643/RemoteInstall-Automated-Testing-of-Windows-Install">RemoteInstall: Automated Testing of Windows Installers on VMWare Infrastructure</a>
		
	</div>
	
	</div>
	

				</div>

                <div class="anchorLink gototop" id="gototop">
                    <a id="ctl00_GoToTop" href="/Articles/24029/Home-Made-Java-Virtual-Machine#_articleTop">Go to top</a>
                </div>
			</div>

		</td>
		<td>
			
			<div id="AT" class="container-article  fixed"> 
				<div class="article">

					<form name="aspnetForm" method="post" action="/Articles/24029/Home-Made-Java-Virtual-Machine" id="aspnetForm" style="margin:0;padding:0">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="rgTw9fLMhnhf23mRTSZiZl5bgmo948bboCwZ6D5PbJAw+iem6bGY6drL2TjYX6ZadZAXX7rih9mJvdQlOFz33v0Rxe7UKTu1JsTdV/WHharpTrIJyuh0n/SkpVRbZPcJnFq28nsvxBwvikr8gNZXr1o6OVJPQags5JfRVJePvJAs8/cKDvJLGFYLLHAxXq/ziDdnpZ48TxG6OHiIwXe4WaoeFn/+Z1XVpMc6EJpkQf/I7ayv08pEdMfBGiE6UoDfqtpyae99h+6kEKmKrIikzviKI2uePayIO/fGT4Nzfgvplp67kEOA5BIQ+nFU2E9mPbLVHOO0H6TCQE0aNVi02kqvOn2gIFZa7pJWt2/srDow23WFUr7AJOdkBqkEGatn1EHcLlXxjcokO/HbkZBzuCRbx6mPlnlq/8LzR+59bp0zmyBSMh57wFigokqJlfqrbqBCb7tjUUs33UhWpSCwNbH0j6Yy128UfndT2MxUJqK3+7FTVT4Vba8wdkcuVVbuWVIRdxx3RAzVTFeEG0FPmX0N19zS7Ul7PhnQzp3hZhxapRak6Oqep1hNShZ/Jg9xH9kGG0l6t8x/Ss467eF7YbfidCQPJQSxgElq79YVCMqi0IOdr31COPzK7s4gX3wfdHuxylSfI5bQhjeXXtwAwwN/5oEbjMX0wOKe/9Hb77ja30yFwmnlAG2dLeQgoX2i114AkenKNGmISl3xXjyOStL05ifjWcRGzsSre6yaG23jYuJrqNzM6wEp1VK6mM1vfJAI74SQKYf/MgoPy+3iZEQOI4Hvo757jMLVlseTWdAH0oA2JJxSmGOBRlGWsE0MqWvx4P8YYfoBPYFZw0AwDf88LKmYRwHp2HsmocOOG+P5IJKoeb8Vpkj+0pZhrDN1aKdenI2tyE0XYpHpcnEnuT4Y4uxIqGimb4tLEGVaNuk2cNid8GPMqVTxS+vem1PFU+e0/TQEKMREMrFUWzW1ae1xMPyZgGXmF7ML3kRbIGSeQ3maNm5QMGm+yAqGtfBS7t3rJSs0IVTDVINEKGH9V26n9XKwRqFq2DUj/qZRmSatBKelX55MSD2Fcs/vaVaVBIn7Ucvgkgh8QlTU8yyovOZtnW+77yUk/i9EabBge0DY1ufVjSTTnQYRck7CmZ2F5fqry5E+WEUanuD3gEmAhjdrgDhFLAE4wPnWdrLoq5+GpNNkS42xWxg9PxhgTMAuxRBq2wd2ccy09XumC4sAzHK+F2+GMLGbv5quhyFxSAzEMNzILZ3gtxA8tYKDHkLwhOGZSjDrNSW8ZPE52cockAJisIeXSe77RSSH5QFNtCQ4nVT87E5B3KDaskJpYI3rvkzwt9OZt/+aaJBvyJ1wpSkRb4Lp5dI0QWkEOqfNH7N8kcfNziPkLAguhhKfXZjIMDvJAO+qHfK5kC2s611+PgmLi4dylavm1QNAPj1hC4r6Nih3M595WcETXrM55XGxQAgigE3XB84U4xtzFdT+/GlYAGYjI1IylnCHOerN/XzTg+HjsYawyAfJU8QWbtjRPzCJtiQR5DPt78yGVgu1i97qWYTZpbYTQQme5gZ8W+5hVZZWhrkcwV1xwlBS1Fvdcvov915jlFTw3HVl84Y/rf84XD/YrgkCljUpuG/ZrbV2UTkHq1p2bGyIuaFYH6Irxk8IFTjAvgpJ00Iwb6rsmLkWco0zqNIHx28uZYA9gp2Zwg5XW+fmQoX6YavKshQkO0WqVFRD3+OmdpsTZ1xxBM+Lk9+9IdpO1u93lG+wmK4sumNIPtGyHBctQOv4ZJsoFh8k8XfL7CQ0OsVYMtj37HjhKVbLIcz7Goz3dS1dJWz43COzjY3GqKnKRUHoL2MLBznwMAXlOOJG59sWTIHrIxHKtG4pdeFnQf0E8FhWaZORY9yAKd5W6w3cymwSC7QOF2q+yZeoM6g869bRQBhFs/dRXYdI9UNiC2+MRTeMPmD1oAE1b0OVgVas4uJPAo0OiVdVQQy4udcLVjDh0PD3cHTCzAZebeCGrSaPUHKYd/uBPLp2jbRKHZg7WQ3b3YPwHo7/4HbAfzPwnoGbllw8RDJKd5sKIwvi/dDu9TVwsY3tu+7FFGmBYKN96MZRAOQXFifOQ8uOS0xIgBAE9eqMHlOKOZAC45D0odM4hIwXXgudMibfssNdnb0wBcsDBZPfNrBLD8HPUPV6KaiFZhaQRmuI+z4=" />
</div>

<div>

	<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="10C1FD69" />
</div>

					
					 
					<div class="header">
					    <a name="Main"></a>

					    
					    <a name="_articleTop" id="_articleTop"></a>
					    <div class="title">
					        
					        <h1 id="ctl00_ArticleTitle" itemprop="name">Home Made Java Virtual Machine</h1> 
					    </div>

                        <div style="height:34px">
					        
					        <div class="entry float-left">
                                <img src="http://www.codeproject.com/script/Membership/ProfileImages/{fa071df0-d6f3-4e1f-b0a1-2044d69afb94}.jpg" id="ctl00_avatar" style="float:left;height:48px;margin-right:10px" />
                                <div class="float-left">

						            <span class="author"><a href="/script/Membership/View.aspx?mid=115829" rel="author"><span itemprop="author" itemscope itemtype="http://schema.org/Person"><span itemprop="name">Maruf Maniruzzaman</span></span></a></span>, 
						            <span class="date" itemprop="dateModified" 
                                        content="2008-03-17 05:09:00">
							            17 Mar 2008</span>
			
                                    <a id="ctl00_LicenseLink" title="The GNU General Public License (GPLv3)" class="license" href="http://www.opensource.org/licenses/gpl-3.0.html">GPL3</a><div id="ctl00_CurRat" class="tooltip anchorLink" style="cursor:pointer;margin-top: 5px" name="CurRat_24029">
				
							            

<table cellpadding="0" cellspacing="0" class="small-text" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating"> 
<tr>
	
	<td class="nowrap">

		
			<meta itemprop="bestRating" content="5"> 
			<meta itemprop="worstRating" content="1">
		

		<span id="ctl00_ArticleRating_VI">
		<div class="nowrap rating-stars-large" style="height:21px;width:119px;position:relative;">
	<div class="clipped align-left float-left" style="height:19px;width:117px;">
		<img src="//dj9okeyxktdvd.cloudfront.net/script/Ratings/Images/stars-fill-lg.png" style="border-width:0px;" />
	</div><div class="clipped" style="height:19px;width:2px;position:relative;">
		<img src="//dj9okeyxktdvd.cloudfront.net/script/Ratings/Images/stars-empty-lg.png" style="border-width:0px;position:absolute;top:0;right:0;" />
	</div>
</div>
		</span>

		
	</td>
	
	<td id="ctl00_ArticleRating_VR" class="nowrap">
		&nbsp;
		<span id="ctl00_ArticleRating_VotesR">&nbsp;<span itemprop="ratingValue" class="rating">4.91</span> (<span itemprop="ratingCount" class="count">74</span> votes)</span>
		
	</td>

</tr>

</table>


							            <div id="ctl00_RB" class="speech-bubble-container-up">
								            <div class="speech-bubble-up" style="width:150px !important">
									                        
<div>
<table class="feature" width="100%" height="50px" title="Voting Distribution. Recent data only" cellpadding="0" cellspacing="0"><tr class="chart-row"><td class="chart-column rating-ignore-vote" title="Outside deviation limits - not included in score."><img src="//dj9okeyxktdvd.cloudfront.net/script/Ratings/Images/pollcol.gif" width="20pxpx" height="1px" border="0px" alt="2 votes, 2.7%" title="2 votes, 2.7%" /><br /><span title="2 votes">1</span></td>
<td class="chart-column rating-ignore-vote" title="Outside deviation limits - not included in score."><img src="//dj9okeyxktdvd.cloudfront.net/script/Ratings/Images/pollcol.gif" width="20pxpx" height="1px" border="0px" alt="1 vote, 1.4%" title="1 vote, 1.4%" /><br /><span title="1 vote">2</span></td>
<td class="chart-column rating-ignore-vote" title="Outside deviation limits - not included in score."><img src="//dj9okeyxktdvd.cloudfront.net/script/Ratings/Images/pollcol.gif" width="20pxpx" height="1px" border="0px" alt="1 vote, 1.4%" title="1 vote, 1.4%" /><br /><span title="1 vote">3</span></td>
<td class="chart-column"><img src="//dj9okeyxktdvd.cloudfront.net/script/Ratings/Images/pollcol.gif" width="20pxpx" height="2px" border="0px" alt="3 votes, 4.1%" title="3 votes, 4.1%" /><br /><span title="3 votes">4</span></td>
<td class="chart-column"><img src="//dj9okeyxktdvd.cloudfront.net/script/Ratings/Images/pollcol.gif" width="20pxpx" height="50px" border="0px" alt="66 votes, 90.4%" title="66 votes, 90.4%" /><br /><span title="66 votes">5</span></td>
</tr></table><div class="small-text align-center">4.91/5 - 74 votes</div><div class="small-text align-center subdue">4 removed</div><div class="small-text align-center subdue">μ 4.67, σ<sub>a</sub> 1.61 [<a href="/KB/FAQs/RatingReputationFAQ.aspx#noisefilter">?</a>]</div>
</div>
								            </div>
								            <div class="speech-bubble-pointer-up">
									            <div class="speech-bubble-pointer-up-inner"></div>
								            </div>
							            </div>
						            </div>
                                </div>
					        </div>

                            
						    <div id="ctl00_RateArticleRow" class="float-right align-right voting-bar">
						        <div id="ctl00_RateArticle_RateItemWrapper" class="container-rating small-text" name="RateItem_24029">

	<table width="100%" cellpadding="0" cellspacing="0" class="small-text">
	<tr>
		<td id="ctl00_RateArticle_VoteResultDiv" class="rating-result align-right">
			<span class="align-right"></span>
			<img class="loaderImg" width="16px" alt="loading..." height="16px" 
				src="/Images/animated_loading_blue.gif" style="display:none;" /> 
		</td>

	
		<td class="voteTbl" style="white-space:nowrap" align="right">
			<table class="small-text">
			<tr>
				<td id="ctl00_RateArticle_RateText" class="rating-prompt">
					Rate this:
				</td>

				
				<td id="ctl00_RateArticle_VoteFormDiv" class="nowrap rating-stars-voter-large">
					

					<span id="ctl00_RateArticle_RB" class="tooltip ajaxHist radio voting">
						<span id="ctl00_RateArticle_VoteRBL"><input id="ctl00_RateArticle_VoteRBL_0" type="radio" name="ctl00$RateArticle$VoteRBL" value="1" /><input id="ctl00_RateArticle_VoteRBL_1" type="radio" name="ctl00$RateArticle$VoteRBL" value="2" /><input id="ctl00_RateArticle_VoteRBL_2" type="radio" name="ctl00$RateArticle$VoteRBL" value="3" /><input id="ctl00_RateArticle_VoteRBL_3" type="radio" name="ctl00$RateArticle$VoteRBL" value="4" /><input id="ctl00_RateArticle_VoteRBL_4" type="radio" name="ctl00$RateArticle$VoteRBL" value="5" /></span> 

						
					</span>

				</td>

				
				<td style="padding-left:5px">	
					<input type="submit" name="ctl00$RateArticle$SubmitRateBtn" value="Vote!" id="ctl00_RateArticle_SubmitRateBtn" class="button" />
				</td>
			</tr>
			</table>
			
		</td>
	</tr>
	</table>
	<div class="hover-container">
		
        <div id="ctl00_RateArticle_RSU" class="rating-comment align-left float-right">
            <div class="padded">
            Please <a id="ctl00_RateArticle_SignUp" href="https://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign up or sign in</a> to vote.
            </div>
        </div>
	</div>
</div>
						    </div>
						    	

						    	
                            <div class="float-right" style="margin: 4px 20px 0 0">
						        
                            </div>                    
						    	
                        </div>

   					    
                        <div id="ctl00_description" class="summary">Functional java virtual machine - can run java applications for most of the instructions.</div>			

                    </div>
                    
					
					

					

					
					
					

						
					

					

						
						<div id="contentdiv" class="text" itemprop="articleBody">
						



<ul class="Download">
<li><a href="/KB/cpp/jvm/kjvm.zip">Download JVM Source Code kjvm.zip - 39.65 KB</a> </li>

<li><a href="/KB/cpp/jvm/seminar.zip">Download seminar presentation - 229.95 KB</a> </li>
</ul>

<h2>Introduction </h2>

<p>Back in year 2004 I had to choose a thesis topic as a prerequisite of completion of my undergraduate course in Computer Science and Engineering. I had choosen Process Migration. And our teacher Mahmud Shahriar Hossain agreed to supervise my work. My partner was Md. Helal Uddin. As part of the thesis I had to implement a Java Virtual Machine. I wanted to write an article since then. But it never actually happened. Today (March 2) is my birth day and I want to start it. The virtual machine is also used in my new project <a href="http://morpheus.kuashaonline.com/">Morpheus </a>- a prototype of Silverlight 1.1. The seminar presentation downloadable from above link shows how a JVM works. You may also look at the JVM source code from above link. Please note that most the implementation decision taken may not match with other commercially available JVM implementation. Whenever JVM Spec is found to say nothing, the most easiest approach is taken to save time. </p>

<h2>Java Virtual Machine Parts</h2>
<img height="467" src="/KB/cpp/jvm/jvm_parts.jpg" width="626" /> 
<h2>Class File Structure </h2>

<p>The java virtual machine needs an application that is made up of collection of java classes. At the beginning of any class there is a defined structure like <code>JavaClassFileFormat</code>. </p>

<pre>     <span class="code-keyword">struct</span>  JavaClassFileFormat 
     { 
         u4 magic; 
         u2 minor_version; 
         u2 major_version; 
         u2 constant_pool_count; 
         cp_info **constant_pool; <span class="code-comment">//</span><span class="code-comment">[constant_pool_count-1]; 
</span>         u2 access_flags; 
         u2 this_class; 
         u2 super_class; 
         u2 interfaces_count; 
         u2* interfaces; <span class="code-comment">//</span><span class="code-comment">[interfaces_count]; 
</span>         u2 fields_count; 
         field_info_ex *fields; <span class="code-comment">//</span><span class="code-comment">[fields_count]; 
</span>         u2 methods_count; 
         method_info_ex* methods; <span class="code-comment">//</span><span class="code-comment">[methods_count]; 
</span>         u2 attributes_count; 
         attribute_info** attributes; <span class="code-comment">//</span><span class="code-comment">[attributes_count]; 
</span>     };</pre>

<p>Following are the structures used in the format. They represents constant pool (constant values used in class files), fields, methods and attributes in a class file. I'll describe them in details later. </p>

<pre>     <span class="code-keyword">struct</span> cp_info 
     { 
         u1 tag; 
         u1* info; 
     }; 
 
     <span class="code-keyword">struct</span> field_info 
     { 
         u2 access_flags; 
         u2 name_index; 
         u2 descriptor_index; 
         u2 attributes_count; 
         attribute_info* attributes; <span class="code-comment">//</span><span class="code-comment">[attributes_count]; 
</span>     }; 
     
     <span class="code-keyword">struct</span> method_info 
     { 
         u2 access_flags; 
         u2 name_index; 
         u2 descriptor_index; 
         u2 attributes_count; 
         attribute_info* attributes; <span class="code-comment">//</span><span class="code-comment">[attributes_count]; 
</span>     }; 
     
     <span class="code-keyword">struct</span> attribute_info
     {
         u2 attribute_name_index;
         u4 attribute_length;
         u1* info;<span class="code-comment">//</span><span class="code-comment">[attribute_length];
</span>     };</pre>

<p>We first load the class file in memory as raw byte and then use <code>JavaClass</code> object to parse the raw bytes and identify the fields, methods, exception table etc. The <code>JavaClass</code> class represent a class in memory in structured form. It holds a pointer to the raw byte stream that was loaded from class file. </p>

<h2>Java Class in Memory</h2>
Here we just inherit the <code>JavaClassFileFormat</code> for simplicity of storing the values in in memory class representation. We must parse the raw class file in memory to get the values for <code>JavaClassFileFormat</code> fields. 
<pre>    <span class="code-keyword">class</span> JavaClass: <span class="code-keyword">public</span> JavaClassFileFormat
    {
    <span class="code-keyword">public</span>:
        JavaClass(<span class="code-keyword">void</span>);
        <span class="code-keyword">virtual</span> ~JavaClass(<span class="code-keyword">void</span>);
    
    <span class="code-keyword">public</span>:
        <span class="code-keyword">virtual</span> BOOL LoadClassFromFile(CString lpszFilePath);
        <span class="code-keyword">void</span> SetByteCode(<span class="code-keyword">void</span>* pByteCode);
    
        BOOL ParseClass(<span class="code-keyword">void</span>);
        BOOL ParseInterfaces(<span class="code-keyword">char</span>* &amp;p);
        BOOL ParseFields(<span class="code-keyword">char</span>* &amp;p);
        BOOL ParseMethods(<span class="code-keyword">char</span>* &amp;p);
        BOOL ParseAttributes(<span class="code-keyword">char</span>* &amp;p);
        BOOL GetConstantPool(u2 nIndex, cp_info&amp; const_pool);
    
        BOOL GetStringFromConstPool(<span class="code-keyword">int</span> nIndex,CString&amp; strValue);
        CString GetName(<span class="code-keyword">void</span>);
        CString GetSuperClassName(<span class="code-keyword">void</span>);
        BOOL ParseMethodCodeAttribute(<span class="code-keyword">int</span> nMethodIndex, Code_attribute* pCode_attr);
        <span class="code-keyword">int</span> GetMethodIndex(CString strMethodName, CString strMethodDesc,
              JavaClass* &amp;pClass);
        <span class="code-keyword">int</span> GetFieldIndex(CString strName, CString&amp; strDesc);
        <span class="code-keyword">void</span> SetClassHeap(ClassHeap *pClassHeap){<span class="code-keyword">this</span>-&gt;m_pClassHeap=pClassHeap;}
        <span class="code-keyword">virtual</span> u4 GetObjectSize(<span class="code-keyword">void</span>);
        <span class="code-keyword">virtual</span> u4 GetObjectFieldCount(<span class="code-keyword">void</span>);
        JavaClass* GetSuperClass(<span class="code-keyword">void</span>);
        BOOL CreateObject(u2 index, ObjectHeap *pObjectHeap, Object&amp; object);
        BOOL CreateObjectArray(u2 index, u4 count, ObjectHeap *pObjectHeap,
           Object&amp; object);
    <span class="code-keyword">private</span>:
        <span class="code-sdkkeyword">size_t</span> m_nByteCodeLength;
        <span class="code-keyword">void</span> *m_pByteCode;
        u2    m_nObjectFieldsCount;
        BOOL ParseConstantPool(<span class="code-keyword">char</span>* &amp;p);
        <span class="code-keyword">int</span> GetConstantPoolSize(<span class="code-keyword">char</span>* p);
        ClassHeap *m_pClassHeap;
    };</pre>

<p>To do that we first load the file in memory and then call the <code>ParseClass</code> method which is shown in the next section. </p>

<h2>Class Loader </h2>

<p>As there are some variable length fields it is not possible to directly load the structure. So we load the values one by one. First we load the value of magic which is an unsigned integer (u4) value. It must be value of 0xCafeBabe. If it is not the class file may be either corrupted or not a java class file at all. Then we load other values and structures. To load structures we first load the count and then load the structure. For example first we load short (u2) value constant_pool_count and then load that number of constant pool. To parse I used definitions getu4(p) or similar which just picks 4 bytes starting at p and returns the unsigned int value. To parse structures hare use sepaate methods like <code>ParseConstantPool</code>. It takes the <em>reference</em> of the byte stream pointer and increments in that class. I did this only for simplicity. It would be more readable if I'd return the total length and increent in ParseClass method but that would me less managable. </p>

<pre>    

    BOOL JavaClass::ParseClass(<span class="code-keyword">void</span> ) 
    { 
        <span class="code-comment">//</span><span class="code-comment">just to be safe 
</span>        <span class="code-keyword">if</span> (m_pByteCode==NULL || 
                m_nByteCodeLength &lt; <span class="code-keyword">sizeof</span> (JavaClassFileFormat)+20) 
            <span class="code-keyword">return</span> FALSE; 
        <span class="code-keyword">char</span> *p=( <span class="code-keyword">char</span> *)m_pByteCode; 
        magic = getu4(p); p+=4; 
        ASSERT(magic == 0xCAFEBABE); 
            
        <span class="code-keyword">if</span>(magic != 0xCAFEBABE)
            <span class="code-keyword">return</span> FALSE;
                
        minor_version=getu2(p); p+=2; 
        major_version=getu2(p); p+=2; 
        constant_pool_count=getu2(p); p+=2; 

        <span class="code-keyword">if</span> (constant_pool_count&gt;<span class="code-digit">0</span>) 
            ParseConstantPool(p); 

        access_flags=getu2(p); p+=2; 
        this_class=getu2(p); p+=2; 
        super_class=getu2(p); p+=2; 
        interfaces_count=getu2(p); p+=2; 

        <span class="code-keyword">if</span> (interfaces_count&gt;<span class="code-digit">0</span>) 
            ParseInterfaces(p); 

        fields_count=getu2(p); p+=2; 

        <span class="code-keyword">if</span> (fields_count &gt; <span class="code-digit">0</span>) 
            ParseFields(p); 

        methods_count = getu2(p);p+=2; 
            
        <span class="code-keyword">if</span> (methods_count &gt; <span class="code-digit">0</span>) 
        { 
            ParseMethods(p); 
        } 
        attributes_count = getu2(p);p+=2; 
            
        <span class="code-keyword">if</span> (attributes_count &gt; <span class="code-digit">0</span>) 
            ParseAttributes(p); 
            
        <span class="code-keyword">return</span> <span class="code-digit">0</span>; 
    }</pre>

<h2>Constant Pool</h2>

<p>In a java class several constant value is stored. It stores numeric, string and reference values in a pool and those are used in machine codes known as 'Java Byte Code'. Constant pool contains constant_pool_count items in a sequential list of following structure. </p>

<pre>    <span class="code-keyword">struct</span> cp_info
    {
        u1 tag;
        u1* info;
    };</pre>

<p>Constant pool information structure starts with one byte of tag information that indicates the type of the constant pool. Constant pool structure length is variable depending on the type of constant. Constant pool tag value can be one of the following values depending on the type of constant. </p>

<pre>    <span class="code-preprocessor">#define</span> CONSTANT_Integer  <span class="code-digit">3</span>  
    <span class="code-preprocessor">#define</span> CONSTANT_Float  <span class="code-digit">4</span>  
    <span class="code-preprocessor">#define</span> CONSTANT_Long  <span class="code-digit">5</span>  
    <span class="code-preprocessor">#define</span> CONSTANT_Double  <span class="code-digit">6</span>  
    <span class="code-preprocessor">#define</span> CONSTANT_Utf8  <span class="code-digit">1</span>  
    <span class="code-preprocessor">#define</span> CONSTANT_String  <span class="code-digit">8</span>  
    
    <span class="code-preprocessor">#define</span> CONSTANT_Class  <span class="code-digit">7</span>  
    <span class="code-preprocessor">#define</span> CONSTANT_Fieldref  <span class="code-digit">9</span>  
    <span class="code-preprocessor">#define</span> CONSTANT_Methodref  <span class="code-digit">10</span>  
    <span class="code-preprocessor">#define</span> CONSTANT_InterfaceMethodref  <span class="code-digit">11</span>  
    <span class="code-preprocessor">#define</span> CONSTANT_NameAndType  <span class="code-digit">12</span></pre>

<p>Depending on the value of tag we can cast the cp_info structure in more precise structures listed here. </p>

<h3>CONSTANT_Integer_info</h3>

<p>If tag value equals <code>CONSTANT_Integer</code> in cp_info structure then it is an integer constant. We can cast the cp_info structure in following structure. </p>

<pre>    <span class="code-keyword">struct</span> CONSTANT_Integer_info {
        u1 tag;
        u4 bytes;
    };</pre>

<p>This structure does not have any reference to any other constant. It represents direct 4 byte integer value. </p>

<h3>CONSTANT_Float_info</h3>

<p>If tag value equals <code>CONSTANT_Float</code> in cp_info structure then it is a float constant. We can cast the cp_info structure in following structure. </p>

<pre>    <span class="code-keyword">struct</span> CONSTANT_Float_info {
        u1 tag;
        u4 bytes;
    };</pre>

<p>It is a direct value constant without any reference. </p>

<h3>CONSTANT_Long_info</h3>

<p>If tag value equals <code>CONSTANT_Long</code> in cp_info structure then it is a long constant. We can cast the cp_info structure in following structure. </p>

<pre>    <span class="code-keyword">struct</span> CONSTANT_Long_info {
        u1 tag;
        u4 high_bytes;
        u4 low_bytes;
    };</pre>

<p>It is a direct value constant without any reference. It uses two four bute values to construct the 8 byte long value. </p>

<h3>CONSTANT_Long_info</h3>

<p>If tag value equals <code>CONSTANT_Double</code> in cp_info structure then it is a double constant. We can cast the cp_info structure in following structure. </p>

<pre>    <span class="code-keyword">struct</span> CONSTANT_Double_info {
        u1 tag;
        u4 high_bytes;
        u4 low_bytes;
    };</pre>

<p>It is a direct value constant without any reference. It uses two four bute values to construct the 8 byte double value. </p>

<h3>CONSTANT_Utf8_info</h3>

<p>If tag value equals <code>CONSTANT_Utf8</code> in cp_info structure then it is a utf8 string constant. We can cast the cp_info structure in following structure. </p>

<pre>    <span class="code-keyword">struct</span> CONSTANT_Utf8_info {
        u1 tag;
        u2 length;
        u1* bytes;<span class="code-comment">//</span><span class="code-comment">[length];
</span>    };</pre>

<p>It is a direct value constant without any reference. The short value <code>length</code> defines the length of the byte array followed by <code>length</code> number of bytes. </p>

<h3>CONSTANT_String_info</h3>

<p>If tag value equals <code>CONSTANT_String</code> in cp_info structure then it is a string <em>reference</em> constant. We can cast the cp_info structure in following structure. </p>

<pre>    <span class="code-keyword">struct</span> CONSTANT_String_info {
        u1 tag;
        u2 string_index;
    };</pre>

<p>It is a reference value constant. The short value <code>string_index</code> refers to a <code>CONSTANT_Utf8_info</code> index in the constant pool. </p>

<h3>CONSTANT_Class_info</h3>

<p>If tag value equals <code>CONSTANT_Class</code> in cp_info structure then it is a class <em>reference</em> constant. We can cast the cp_info structure in following structure. </p>

<pre>    <span class="code-keyword">struct</span> CONSTANT_Class_info {
         u1 tag;
           u2 name_index;
    };</pre>

<p>It is a reference value constant. The short value <code>name_index</code> refers to a <code>CONSTANT_Utf8_info</code> index in the constant pool that is the fully qualified name (ie <code>java/lang/String</code>) of the class- dot replaced by slash. </p>

<h3>CONSTANT_Fieldref_info</h3>

<p>If tag value equals <code>CONSTANT_Fieldref</code> in cp_info structure then it is a field <em>reference</em> constant. We can cast the cp_info structure in following structure. </p>

<pre>    <span class="code-keyword">struct</span> CONSTANT_Fieldref_info {
        u1 tag;
        u2 class_index;
        u2 name_and_type_index;
    };</pre>

<p>It is a reference value constant. The short value <code>class_index</code> refers to a <code>CONSTANT_Class_info</code> index in the constant pool and <code>name_and_type_index</code> refers to a string index in the constant pool that is the fully qualified name (ie <code>java/lang/String@valueOf(F)Ljava/lang/String;</code>) of the class- dot replaced by slash. </p>

<h3>CONSTANT_Methodref_info</h3>

<p>If tag value equals <code>CONSTANT_Methodref</code> in cp_info structure then it is a method <em>reference</em> constant. We can cast the cp_info structure in following structure. </p>

<pre>    <span class="code-keyword">struct</span> CONSTANT_Methodref_info {
        u1 tag;
        u2 class_index;
        u2 name_and_type_index;
    };</pre>

<p>It is a reference value constant. The short value <code>class_index</code> refers to a <code>CONSTANT_Class_info</code> index in the constant pool and <code>name_and_type_index</code> refers to a string index in the constant pool that is the fully qualified name (ie <code>java/lang/String@valueOf(F)Ljava/lang/String;</code>) of the class- dot replaced by slash. </p>

<h3>CONSTANT_InterfaceMethodref_info</h3>

<p>If tag value equals <code>CONSTANT_InterfaceMethodref</code> in cp_info structure then it is an interface method <em>reference</em> constant. We can cast the cp_info structure in following structure. </p>

<pre>    <span class="code-keyword">struct</span> CONSTANT_InterfaceMethodref_info {
        u1 tag;
        u2 class_index;
        u2 name_and_type_index;
    };</pre>

<p>It is a reference value constant. The short value <code>class_index</code> refers to a <code>CONSTANT_Class_info</code> index in the constant pool and <code>name_and_type_index</code> refers to a string index in the constant pool that is the fully qualified name (ie <code>java/lang/String@valueOf(F)Ljava/lang/String;</code>) of the class- dot replaced by slash. </p>

<h3>CONSTANT_NameAndType_info</h3>

<p>If tag value equals <code>CONSTANT_NameAndType</code> in cp_info structure then it is an interface method <em>reference</em> constant. We can cast the cp_info structure in following structure. </p>

<pre>    <span class="code-keyword">struct</span> CONSTANT_NameAndType_info {
        u1 tag;
        u2 name_index;
        u2 descriptor_index;
    };</pre>

<p>It is a reference value constant. The short value <code>name_index</code> refers to a string index in the constant pool and <code>descriptor_index</code> refers to another string index in the constant pool. </p>

<h3>Parsing constant pool</h3>

<p>Here we set the values of constant pool list pointers. When we need to retrieve the actual value we look at the tag and pick the value directly. </p>

<pre>    BOOL JavaClass::ParseConstantPool(<span class="code-keyword">char</span>* &amp;p)
    {    
        constant_pool = <span class="code-keyword">new</span> cp_info*[constant_pool_count-<span class="code-digit">1</span>];
        <span class="code-keyword">if</span>(constant_pool == NULL) <span class="code-keyword">return</span> FALSE;    
        <span class="code-keyword">for</span>(<span class="code-keyword">int</span> i=1;i&lt;constant_pool_count;i++)
        {
            <span class="code-comment">//</span><span class="code-comment">We set the constant pointer here
</span>            constant_pool[i]=(cp_info*)p;
                
            <span class="code-comment">//</span><span class="code-comment">We now calculate constant size. If it is an integer we get size = 5        
</span>            <span class="code-keyword">int</span> size = GetConstantPoolSize(p);
            p+= size;

            <span class="code-comment">//</span><span class="code-comment"> If constant type is long or double constant pool takes two entries.
</span>            <span class="code-comment">//</span><span class="code-comment"> Second entry is not used by virtual machine but kept NULL to walk
</span>            <span class="code-comment">//</span><span class="code-comment"> constant pool correctly.
</span>            <span class="code-keyword">if</span>(constant_pool[i]-&gt;tag == CONSTANT_Long || constant_pool[i]-&gt;tag == 
              CONSTANT_Double)
            {
                constant_pool[i+1]=NULL;
                i++;
            }
        }
        <span class="code-keyword">return</span> TRUE;
    }</pre>

<h2>Interfaces</h2>

<p>In the <code>interfaces</code> field of a class there are <code>interfaces_count</code> number of short (u2) values. Each value is a <em>reference</em> to a constant pool entry of type <code>CONSTANT_Class</code>. We parse them and store in our in-memory object- </p>

<pre>    BOOL JavaClass::ParseInterfaces(<span class="code-keyword">char</span>* &amp;p)
    {    
        interfaces = <span class="code-keyword">new</span> u2[interfaces_count];        
        <span class="code-keyword">for</span>(<span class="code-keyword">int</span> i=0;i&lt;interfaces_count;i++)
        {
            interfaces[i] = getu2(p); p+=2;
        }

        <span class="code-keyword">return</span> TRUE;
    }</pre>

<h2>Fields</h2>

<p>A class may contain zero, one or more fields. The actual number is stored in the <code>fields_count</code> field. A list of <code>field_info</code> structure followes this value. </p>

<pre>    <span class="code-keyword">struct</span> field_info
    {
        u2 access_flags;
        u2 name_index;
        u2 descriptor_index;
        u2 attributes_count;
        attribute_info* attributes;<span class="code-comment">//</span><span class="code-comment">[attributes_count];
</span>    };</pre>

<p>The short value <code>access_flags</code> describes the allowed field access. Here is the possible access flags values which is shared also by methods and classes- </p>

<pre>    <span class="code-preprocessor">#define</span> ACC_PUBLIC  0x0001  
    <span class="code-comment">/*</span><span class="code-comment">Declared public; may be accessed from outside its package.  */</span>
    
    <span class="code-preprocessor">#define</span> ACC_PRIVATE  0x0002  
    <span class="code-comment">/*</span><span class="code-comment">Declared private; accessible only within the defining class.  */</span>
    
    <span class="code-preprocessor">#define</span> ACC_PROTECTED  0x0004  
    <span class="code-comment">/*</span><span class="code-comment">Declared protected; may be accessed within subclasses.  */</span>
    
    <span class="code-preprocessor">#define</span> ACC_STATIC  0x0008  <span class="code-comment">/*</span><span class="code-comment">Declared static.  */</span>
    
    <span class="code-preprocessor">#define</span> ACC_FINAL  0x0010  
    <span class="code-comment">/*</span><span class="code-comment">Declared final; may not be overridden.  */</span>
    
    <span class="code-preprocessor">#define</span> ACC_SYNCHRONIZED  0x0020  
    <span class="code-comment">/*</span><span class="code-comment">Declared synchronized; invocation is wrapped in a monitor lock.  */</span>
    
    <span class="code-preprocessor">#define</span> ACC_NATIVE  0x0100  
    <span class="code-comment">/*</span><span class="code-comment">Declared native; implemented in a language other than Java.  */</span>
    
    <span class="code-preprocessor">#define</span> ACC_ABSTRACT  0x0400  
    <span class="code-comment">/*</span><span class="code-comment">Declared abstract; no implementation is provided.  */</span>
    
    <span class="code-preprocessor">#define</span> ACC_STRICT  0x0800  
    <span class="code-comment">/*</span><span class="code-comment">Declared strictfp; floating-point mode is FP-strict  */</span></pre>

<p>The <code>name_index</code> and <code>descriptor_index</code> are reference to two constant pool of type utf8 string. The <code>attributes</code> field defined the attributes of the field. Attributes are described later. Here is how we parse fields in a class's raw bytes- </p>

<pre>    BOOL JavaClass::ParseFields(<span class="code-keyword">char</span>* &amp;p)
    {
        fields = <span class="code-keyword">new</span> field_info_ex[fields_count];
        <span class="code-keyword">if</span>(fields == NULL) <span class="code-keyword">return</span> FALSE;

        <span class="code-keyword">for</span>(<span class="code-keyword">int</span> i=0;i&lt;fields_count;i++)
        {
            fields[i].pFieldInfoBase = (field_info*)p;

            fields[i].access_flags= getu2(p); p+=2; <span class="code-comment">//</span><span class="code-comment">access_flags
</span>            fields[i].name_index= getu2(p);p+=2; <span class="code-comment">//</span><span class="code-comment">
</span>            fields[i].descriptor_index= getu2(p);p+=2; <span class="code-comment">//</span><span class="code-comment">
</span>            fields[i].attributes_count=getu2(p); p+=2;

            <span class="code-keyword">if</span>(fields[i].attributes_count&gt;<span class="code-digit">0</span>)
            {
                <span class="code-comment">//</span><span class="code-comment">skip attributes - we do not need in simple cases
</span>                <span class="code-keyword">for</span>(<span class="code-keyword">int</span> a=0;a&lt;fields[i].attributes_count;a++)
                {
                    u2 name_index=getu2(p); p+=2;
                    <span class="code-comment">//</span><span class="code-comment">printf("Attribute name index = %d\n", name_index);
</span>                    u4 len=getu4(p);p+=4;
                    p+=len;
                }
            }            
        }
        <span class="code-keyword">return</span> TRUE;
    }</pre>

<h2>Methods</h2>

<p>A java class file may contain arbitrary number of methods. The count is stored in <code>methods_count</code> member of class file structure. As it is a two byte field the theoritical upper limit is essentially 2^16. Like fields info, method info structure contains access flags, name index, descriptor index, and attributes. </p>

<pre>    <span class="code-keyword">struct</span> method_info
    {
        u2 access_flags;
        u2 name_index;
        u2 descriptor_index;
        u2 attributes_count;
        attribute_info* attributes;<span class="code-comment">//</span><span class="code-comment">[attributes_count];
</span>    };</pre>

<p>Method body (if any) is stored in an attribute named <code>Code</code>- which contains the actual 'Java Byte Code'. Here is how we parse methods in out virtual machine- </p>

<pre>    <span class="code-comment">//</span><span class="code-comment">TODO: Cashe the findings here
</span>    BOOL JavaClass::ParseMethods(<span class="code-keyword">char</span>* &amp;p)
    {
        methods = <span class="code-keyword">new</span> method_info_ex[methods_count];

        <span class="code-keyword">if</span>(methods == NULL) <span class="code-keyword">return</span> FALSE;
        
        <span class="code-keyword">for</span>(<span class="code-keyword">int</span> i=0;i&lt;methods_count;i++)
        {
            <span class="code-comment">//</span><span class="code-comment">methods[i] = new method_info_ex;
</span>            methods[i].pMethodInfoBase=(method_info*)p;
            methods[i].access_flags= getu2(p);    p+=2; <span class="code-comment">//</span><span class="code-comment">access_flags
</span>            methods[i].name_index = getu2(p); p+=2; <span class="code-comment">//</span><span class="code-comment">name_index
</span>            methods[i].descriptor_index= getu2(p); p+=2; <span class="code-comment">//</span><span class="code-comment">descriptor_index
</span>            methods[i].attributes_count=getu2(p); p+=2;
            
            CString strName, strDesc;
            GetStringFromConstPool(methods[i].name_index, strName);
            GetStringFromConstPool(methods[i].descriptor_index, strDesc);

            TRACE(_T(<span class="code-string">"</span><span class="code-string">Method = %s%s\n"</span>),strName, strDesc);
            
            TRACE(<span class="code-string">"</span><span class="code-string">Method has total %d attributes\n"</span>,methods[i].attributes_count);

            methods[i].pCode_attr=NULL;
            <span class="code-keyword">if</span>(methods[i].attributes_count&gt;<span class="code-digit">0</span>)
            {
                <span class="code-comment">//</span><span class="code-comment">skip attributes
</span>                <span class="code-keyword">for</span>(<span class="code-keyword">int</span> a=0;a&lt;methods[i].attributes_count;a++)
                {
                    u2 name_index=getu2(p); p+=2;
                    
                    TRACE(<span class="code-string">"</span><span class="code-string">Attribute name index = %d\n"</span>, name_index);
                    u4 len=getu4(p);p+=4;
                    p+=len;
                }

                methods[i].pCode_attr = <span class="code-keyword">new</span> Code_attribute;
                ParseMethodCodeAttribute(i, methods[i].pCode_attr);
            }        
        }

        <span class="code-keyword">return</span> TRUE;
    }</pre>

<p>In case of method structure ( and also same in fields structure) I have used <code>method_info_ex</code> instead of <code>method_info</code> structure. This extended structure on pointer to pint to raw method info in the in-memory bytestream of class file. Here with other fields we parse the <code>Code</code> attribute. The details id given later in attributes section. </p>

<h2>Attributes</h2>

<p>In most classes attributes takes most of the space in file. Class has attributes, method has attributes, field has attributes. The raw definition of attribute is like this- </p>

<pre>    <span class="code-keyword">struct</span> attribute_info
    {
        u2 attribute_name_index;
        u4 attribute_length;
        u1* info;<span class="code-comment">//</span><span class="code-comment">[attribute_length];
</span>    };</pre>

<p>The <code>attribute_name_index</code> field is the reference index in the constant pool for string type constant. The <code>attribute_length</code> field is the length of info field- which is another structure depending on the type/ name of the attribute. An arrtibute can be a constant value, exception table or code type. </p>

<h3>Constant value attribute</h3>

<pre>    <span class="code-keyword">struct</span> ConstantValue_attribute {
        u2 attribute_name_index;
        u4 attribute_length;
        u2 constantvalue_index;
    };</pre>

<h3>Code Attribute</h3>

<p>It is also a method specific attribute. The name of the attribute is hardcoded as 'Code'. This attribute has maximum stack and maximum local values of the method. The <code>code</code> field is variable length defined by <code>code_length</code> and it contains the actual 'Java Byte Code'. </p>

<pre>    <span class="code-keyword">struct</span> Code_attribute {
        u2 attribute_name_index;
        u4 attribute_length;
        u2 max_stack;
        u2 max_locals;
        u4 code_length;
        u1* code;<span class="code-comment">//</span><span class="code-comment">[code_length];
</span>        u2 exception_table_length;
        Exception_table* exception_table;<span class="code-comment">//</span><span class="code-comment">[exception_table_length];
</span>        u2 attributes_count;
        attribute_info* attributes;<span class="code-comment">//</span><span class="code-comment">[attributes_count];
</span>    };</pre>

<h4>Exception table structure</h4>

<p>This structure is used to define the exception table for methods. The exception table describes the exception handler depending on the program counter value or offset of byte code. The handler code is also an offset in the byte code. </p>

<pre>    <span class="code-keyword">struct</span> Exception_table
    {
        u2 start_pc;
        u2 end_pc;
        u2  handler_pc;
        u2  catch_type;
    };</pre>

<p>The field catch_type is a reference to a constant pool entry that describes the type of the exception- for example reference to a class named 'java/lang/Exception'. </p>

<h2>Java Instruction Set</h2>

<p>Java has more than 200 instructions. The java language file, when compiled, is converted to a class file that contains intrtuctions as byte codes. If we have a method like this- </p>

<pre>    <span class="code-keyword">public</span> <span class="code-keyword">int</span> mul(<span class="code-keyword">int</span> a, <span class="code-keyword">int</span> b)
    {
        <span class="code-keyword">return</span> a * b;
    }</pre>

<p>we will get this method in byte code attribute like this- (java has also assembly like representation for instructions to represent byte codes in human readable format) </p>

<pre>  Code Attribute:
    Stack=2, Locals=3, Args_size=3,  Code Length = <span class="code-digit">4</span>
    Code:
    <span class="code-digit">0</span>:   iload_1
    <span class="code-digit">1</span>:   iload_2
    <span class="code-digit">2</span>:   imul
    <span class="code-digit">3</span>:   ireturn</pre>

<p>Here if we follow the instructions we go like this:</p>

<pre>    <span class="code-digit">0</span>: Push (load) the local variable <span class="code-digit">1</span> on stack
    <span class="code-digit">1</span>: Push the local variable <span class="code-digit">2</span> on stack
    <span class="code-digit">3</span>: Pop two values from stack, <span class="code-keyword">do</span> an integer multipucation <span class="code-keyword">and</span> push the result
    <span class="code-digit">4</span>: Return the integer <span class="code-keyword">value</span> from stack top.</pre>

<p>What we need to do in our virtual machine is load classes and follow the instructions in methods. There are methods to create new objects, to call methods of object. It is also possible to call native methods from a java method. Please refer to source code for most other codes (opcodes.h) or Java Virtual Machine Specification for a complete list. </p>

<h2>Class heap</h2>

<p>In the virtual machine we must maintain a heap where the class definition objects can be stored. I have implemented it as a separate heap for simplity. In this heap we load classes from files and store it in the heap. The <code>ClassHeap</code> class is responsible for maintaining the class heap in meory. </p>

<pre>    <span class="code-keyword">class</span> ClassHeap
    {
        CMapStringToPtr m_ClassMap;
        FilePathManager *pFilePathManager;
    <span class="code-keyword">public</span>:
        ClassHeap(<span class="code-keyword">void</span>);
    <span class="code-keyword">public</span>:
        <span class="code-keyword">virtual</span> ~ClassHeap(<span class="code-keyword">void</span>);
    <span class="code-keyword">public</span>:
        BOOL AddClass(JavaClass* pJavaClass);
        JavaClass* GetClass(CString strClassName);
        BOOL LoadClass(CString strClassName, JavaClass *pClass);


    };</pre>

<p>We store <code>JavaClass</code> objects pointer in the <code>m_ClassMap</code> member using the class name as key. </p>

<h2>Object heap</h2>

<p>Object heap is virtual machine's RAM. All objects are created on object heap and its reference can be stored in another object or on the stack. Any reference is stored in an union type storage named <code>Variable</code>. Any field of a class can be represented using variable object. Anything can be stored in a <code>Variable</code> object. </p>

<pre>    <span class="code-keyword">union</span> Variable
    {
        u1 charValue;
        u2 shortValue;
        u4 intValue;
        f4 floatValue;
        LONG_PTR ptrValue;
        <span class="code-sdkkeyword">Object</span> object;
    };</pre>

<p>Object creation on heap is described later in detail. </p>

<h3>Virtual Machine Stack</h3>

<p>Java instruction set is designed in such a way that it can work with very limited set of registers. Instead it uses its stack very extensively. The JVM stack element is one item regardless of - it may be primitive ype or object type. Only <code><span class="code-keyword">long</span></code> and <code><span class="code-keyword">double</span></code> type takes two stack spaces. The 'Execution Engine' maintains the JVM stack. For example when the execution engine executes <code>iadd</code> instruction it pops two numeric values from the stack and add the values and pushes the result on the stack. The virtual machine has empty stack initially and the stack is populated after the initial thread and the initial method is started for execution. Each method instruction is allowed to operate on stack within a limited boundary of the stack. The compiler sets the upper limit (top) as <code>max_stack</code> field of each methods <code>Code</code> attribute. The lower limit is the top+1 stack position of previous method. This boundary of stack is named as <em>Stack Frame</em> of that method. </p>

<h3>The Stack Frame</h3>

<p>As we mentioned each methods boundary in the JVM stack is known as 'Stack Frame'. Each stack frame reserves positions for the parameters and local variables of that method. If it is not a static method the first parameter is the object reference ( the <code><span class="code-keyword">this</span></code> parameter) of type of the class of the method. The <em>Execution Engine</em> operates between the frame and when the method returns a value it pops every element from the current frame including <code><span class="code-keyword">this</span></code> reference and pushes the return value (if method is not <code><span class="code-keyword">void</span></code> return type) value on the frame of previous frames top. To keep the implementation simple I used slightly different methodology. I used stack of stack. Each frame is stack type and it is pushed on the JVM stack. The stack grows on method invocation and shrinks on method return. </p>

<h3>Local Variables</h3>

<p>In a stack frame local variables takes positions from zero to <code>max_locals</code> - 1 positions or less. If the method is not static the object takes the position zero and other locals follow it. Local variables are accessed using <code>putfield</code> and <code>getfield</code> instructions. </p>

<h3>Native method stack</h3>

<p>Unlike virtual machine stack, native methods stack is not maintained by JVM. It is maintained by the native system. Actually while a native method is being executed the virtual machine component that was managing the java thread waits until the native method completes and returns.</p>

<h2>Runtime Environment</h2>

<p>Each java thread has its own frame stack. All java threads in a process share common class heap and object heap. This things are bundled together in a <code>RuntimeEnvironment</code> object and carried among the execution engine components. </p>

<pre> <span class="code-keyword">class</span> RuntimeEnvironment 
 { 
    <span class="code-keyword">public</span>: 
        Frame *pFrameStack; 
        ClassHeap *pClassHeap; 
        ObjectHeap *pObjectHeap; 
 };</pre>

<h2>Execution Unit</h2>

<p>This is the main module of the JVM. It interprates the instructons. Advanced JVMs may use JIT compiler to convert java instructions into native instruction. But I did not do that because of the complexity of the JIT compiler. When a JVM starts it usually takes initial class name as parameter. Our JVM also takes class name as a parameter. The class heap is then requested to load that class. Then the JVM finds its main method (it can be any name like Entry in case of my first implementation), creates the initial stack frame and requests the execution engine to start execution. The heart of the <em>Execution Unit</em> is the <code>Execute</code> method. Here is the skeleton: </p>

<pre>    u4 ExecutionEngine::Execute(Frame* pFrameStack)
    {
        ASSERT(pFrameStack);
        ASSERT(pFrame);

        Frame* pFrame=&amp;pFrameStack[<span class="code-digit">0</span>];

        DbgPrint(_T(<span class="code-string">"</span><span class="code-string">Current Frame %ld Stack start at %ld\n"</span>),
                pFrame-Frame::pBaseFrame,     pFrame-&gt;stack-Frame::pOpStack );

        <span class="code-keyword">if</span>(pFrame-&gt;pMethod-&gt;access_flags &amp; ACC_NATIVE)
        {
            ExecuteNativeMethod(pFrame);
            <span class="code-keyword">return</span> <span class="code-digit">0</span>;
        }

        u1 *bc=pFrame-&gt;pMethod-&gt;pCode_attr-&gt;code + pFrame-&gt;pc;    
        
        i4 error=0;
        JavaClass *pClass = pFrame-&gt;pClass;

        CString strMethod;
        pClass-&gt;GetStringFromConstPool(pFrame-&gt;pMethod-&gt;name_index, strMethod);

        DbgPrint(_T(<span class="code-string">"</span><span class="code-string">Execute At Class %s Method %s \n"</span>), pClass-&gt;GetName(), strMethod); 
        i4 index=0;
        i8 longVal;
        <span class="code-keyword">while</span>(<span class="code-digit">1</span>)
        {
            <span class="code-keyword">switch</span>(bc[pFrame-&gt;pc])
            {
            <span class="code-keyword">case</span> nop: <span class="code-comment">//</span><span class="code-comment">Do nothing
</span>                pFrame-&gt;pc++;
                <span class="code-keyword">break</span>;
                
            <span class="code-comment">//</span><span class="code-comment">Integer Arithmetic 
</span>            <span class="code-keyword">case</span> iadd: <span class="code-comment">//</span><span class="code-comment">96 : Pop two int values from stack add them and push result
</span>                pFrame-&gt;stack[pFrame-&gt;sp-<span class="code-digit">1</span>].intValue=pFrame-&gt;stack[pFrame-&gt;sp-<span class="code-digit">1</span>].intValue 
                        + pFrame-&gt;stack[pFrame-&gt;sp].intValue;    
                pFrame-&gt;sp--;
                pFrame-&gt;pc++;
                <span class="code-keyword">break</span>;
                
            <span class="code-comment">//</span><span class="code-comment">Method return instructions            
</span>            <span class="code-keyword">case</span> ireturn: 
                <span class="code-comment">//</span><span class="code-comment">172 (0xac) : Pop everything from stack and push return value (int)
</span>                pFrame-&gt;stack[<span class="code-digit">0</span>].intValue=pFrame-&gt;stack[pFrame-&gt;sp].intValue;            
                <span class="code-keyword">return</span> ireturn; <span class="code-comment">//</span><span class="code-comment"> here we break the while loop
</span>                <span class="code-keyword">break</span>;
                
            <span class="code-comment">//</span><span class="code-comment"> Method invokation Instructions
</span>
            <span class="code-comment">//</span><span class="code-comment"> Here actually we do a recursive call to Execute
</span>            <span class="code-comment">//</span><span class="code-comment"> to keep things simple- after the java method return we
</span>            <span class="code-comment">//</span><span class="code-comment"> also return from Execute- some memory waste for simplicity
</span>            <span class="code-keyword">case</span> invokevirtual: <span class="code-comment">//</span><span class="code-comment">182: Invoke a virtual method. 
</span>                <span class="code-comment">//</span><span class="code-comment"> The object reference and parameters are on stack by java instructions
</span>                ExecuteInvoke(pFrame, invokevirtual);
                pFrame-&gt;pc+=3;
                <span class="code-keyword">break</span>;                                            
            }

            <span class="code-comment">//</span><span class="code-comment">Instructions that deal with objects
</span>
            <span class="code-keyword">case</span> _new:<span class="code-comment">//</span><span class="code-comment"> 187 (0xbb)
</span>                ExecuteNew(pFrame);
                pFrame-&gt;pc+=3;
                <span class="code-keyword">break</span>;
            <span class="code-keyword">case</span> putfield: <span class="code-comment">//</span><span class="code-comment">181 (0xb5): Set field in object from stack top
</span>                PutField(pFrame);
                pFrame-&gt;sp-=2;
                pFrame-&gt;pc+=3;
                <span class="code-keyword">break</span>;

            <span class="code-keyword">case</span> getfield: 
                <span class="code-comment">//</span><span class="code-comment">180 (0xb4) Fetch field from object and push on stack
</span>                GetField(pFrame);
                pFrame-&gt;pc+=3;
                <span class="code-keyword">break</span>;
        }
        <span class="code-keyword">return</span> <span class="code-digit">0</span>;
    }</pre>

<h3>Creating object on Object Heap</h3>

<p>An object is usually created by JVM when a <code><span class="code-keyword">new</span></code> or <code>newarray</code> or <code>multinewarray</code> instruction is executed. When a virtual machine creates an object it first calculate the size of the object. To calculate the object size we we first take the <code>fields_count</code> value in the class structure then we add its super classes <code>fields_count</code> value with it then we add super classes super classes <code>fields_count</code> and so on recursively until we reach the final base class java.lang.Object. This way we calculate total fields of the object and add one with it that holds the class pointer in the ClassHeap. Now we multiply the <code><span class="code-keyword">sizeof</span>(Variable)</code> to the count and get number of bytes required for the object. We now allocate the required bytes and return the pointer to that memory in a <code>Variable</code> object on the stack top. Here is the implementation. </p>

<pre>    <span class="code-keyword">int</span> ExecutionEngine::ExecuteNew(Frame* pFrame)
    {
        pFrame-&gt;sp++;
        u1 *bc=pFrame-&gt;pMethod-&gt;pCode_attr-&gt;code;
        u2 index=getu2(&amp;bc[pFrame-&gt;pc+1]);
        <span class="code-keyword">if</span>(!pFrame-&gt;pClass-&gt;CreateObject(
            index, <span class="code-keyword">this</span>-&gt;pObjectHeap, pFrame-&gt;stack[pFrame-&gt;sp].object))
            <span class="code-keyword">return</span> -<span class="code-digit">1</span>;        
        <span class="code-keyword">return</span> <span class="code-digit">0</span>;
    }

    BOOL JavaClass::CreateObject(u2 index, ObjectHeap *pObjectHeap, Object&amp; object)
    {
        <span class="code-keyword">char</span> *cp=(<span class="code-keyword">char</span>*)<span class="code-keyword">this</span>-&gt;constant_pool[index];
        ASSERT(cp[<span class="code-digit">0</span>] == CONSTANT_Class);
        ASSERT(pObjectHeap);
        <span class="code-keyword">if</span>(cp[<span class="code-digit">0</span>] != CONSTANT_Class)
            <span class="code-keyword">return</span> FALSE;

        u2 name_index=getu2(&amp;cp[<span class="code-digit">1</span>]);
        CString strClassName;
        <span class="code-keyword">if</span>(!this-&gt;GetStringFromConstPool(name_index, strClassName))
            <span class="code-keyword">return</span> FALSE;                

        JavaClass *pNewClass=this-&gt;m_pClassHeap-&gt;GetClass(strClassName);
        <span class="code-keyword">if</span>(pNewClass == NULL) <span class="code-keyword">return</span> FALSE;
        object=pObjectHeap-&gt;CreateObject(pNewClass);
        <span class="code-keyword">return</span> TRUE;
    }</pre>

<h3>Setting or getting value in object</h3>

<p>The <code>putfield</code> instruction is used to set a value (from stack) of a field and the <code>getfield</code> instruction is used to load a variables value on the stack. When the execution engine needs to execute a <code>getfield</code> instruction it pops two values from the stack. One value is the object pointer another is field position (zero based index). Here is my implementation: </p>

<pre>    <span class="code-comment">//</span><span class="code-comment"> Gets value or reference from stack and set in object
</span>    <span class="code-keyword">void</span> ExecutionEngine::PutField(Frame* pFrameStack)
    {        
        u2 nIndex = getu2(
            &amp;pFrameStack[<span class="code-digit">0</span>].pMethod-&gt;pCode_attr-&gt;code[pFrameStack[<span class="code-digit">0</span>].pc+1]);
        Variable obj=pFrameStack[<span class="code-digit">0</span>].stack[pFrameStack[<span class="code-digit">0</span>].sp-<span class="code-digit">1</span>];
        Variable value=pFrameStack[<span class="code-digit">0</span>].stack[pFrameStack[<span class="code-digit">0</span>].sp];
        Variable *pVarList=this-&gt;pObjectHeap-&gt;GetObjectPointer(obj.object);
        pVarList[nIndex+1]=value;
    }
    
    <span class="code-comment">//</span><span class="code-comment">Gets the value from variable and push on stack
</span>    <span class="code-keyword">void</span> ExecutionEngine::GetField(Frame* pFrame)
    {    
        <span class="code-comment">//</span><span class="code-comment">TODO: Bug check for long and double
</span>        u2 nIndex = getu2(
            &amp;pFrame-&gt;pMethod-&gt;pCode_attr-&gt;code[pFrame-&gt;pc+1]);
        Variable obj=pFrame-&gt;stack[pFrame-&gt;sp];        
        Variable *pVarList=this-&gt;pObjectHeap-&gt;GetObjectPointer(obj.object);
        pFrame-&gt;stack[pFrame-&gt;sp]=pVarList[nIndex+1];
    }</pre>

<h3>Invoking method</h3>

<p>When execution engine requires a method invocation it needs to creates a new 'Stack Frame' and the <code>pc</code> or Program Counter is set to the first byte of the methods byte code. Before that, the execution engine must save the current methods <code>pc</code> so that it can come back to resume method execution after the callee method returns. Here is our implementation. Please note how we handle static method invocation - simply we do not have the <code><span class="code-keyword">this</span></code> reference on our stack. </p>

<pre>    <span class="code-keyword">void</span> ExecutionEngine::ExecuteInvoke(Frame* pFrameStack, u2 type)
    {
        u2 mi=getu2(
            &amp;pFrameStack[<span class="code-digit">0</span>].pMethod-&gt;pCode_attr-&gt;code[pFrameStack[<span class="code-digit">0</span>].pc+1]);
        Variable objectRef = pFrameStack[<span class="code-digit">0</span>].stack[pFrameStack[<span class="code-digit">0</span>].sp]; 
        <span class="code-keyword">char</span> *pConstPool = (<span class="code-keyword">char</span> *)pFrameStack[<span class="code-digit">0</span>].pClass-&gt;constant_pool[mi];

        ASSERT(pConstPool[<span class="code-digit">0</span>] == CONSTANT_Methodref);
            
        u2 classIndex = getu2(&amp;pConstPool[<span class="code-digit">1</span>]);
        u2 nameAndTypeIndex = getu2(&amp;pConstPool[<span class="code-digit">3</span>]);

        <span class="code-comment">//</span><span class="code-comment">get class at pool index 
</span>        pConstPool = 
            (<span class="code-keyword">char</span> *)pFrameStack[<span class="code-digit">0</span>].pClass-&gt;constant_pool[classIndex];

        ASSERT(pConstPool[<span class="code-digit">0</span>] == CONSTANT_Class);

        u2 ni=getu2(&amp;pConstPool[<span class="code-digit">1</span>]);

        CString strClassName;
        pFrameStack[<span class="code-digit">0</span>].pClass-&gt;GetStringFromConstPool(
                ni, strClassName);


        JavaClass *pClass=pClassHeap-&gt;GetClass(strClassName);
        pConstPool = 
            (<span class="code-keyword">char</span> *)pFrameStack[<span class="code-digit">0</span>].pClass-&gt;constant_pool[nameAndTypeIndex];

        ASSERT(pConstPool[<span class="code-digit">0</span>] == CONSTANT_NameAndType);

        method_info_ex method;        
        method.name_index = getu2(&amp;pConstPool[<span class="code-digit">1</span>]);
        method.descriptor_index = getu2(&amp;pConstPool[<span class="code-digit">3</span>]);
        method.access_flags = <span class="code-digit">0</span>; <span class="code-comment">//</span><span class="code-comment"> set later
</span>
        CString strName, strDesc;
        pFrameStack[<span class="code-digit">0</span>].pClass-&gt;GetStringFromConstPool(
            method.name_index, strName);
        pFrameStack[<span class="code-digit">0</span>].pClass-&gt;GetStringFromConstPool(
            method.descriptor_index, strDesc);

        
        JavaClass *pVirtualClass=pClass;
        <span class="code-keyword">int</span> nIndex=pClass-&gt;GetMethodIndex(strName, strDesc, pVirtualClass);

        memset(&amp;pFrameStack[<span class="code-digit">1</span>],<span class="code-digit">0</span>,<span class="code-keyword">sizeof</span>(pFrameStack[<span class="code-digit">1</span>]));
        pFrameStack[<span class="code-digit">1</span>].pMethod = &amp;pClass-&gt;methods[nIndex];
            
        method.access_flags = getu2((<span class="code-keyword">char</span> *)pFrameStack[<span class="code-digit">1</span>].pMethod);
        <span class="code-keyword">if</span>( ACC_SUPER &amp; method.access_flags)
        {
            pFrameStack[<span class="code-digit">1</span>].pClass = pVirtualClass-&gt;GetSuperClass();
        }
        <span class="code-keyword">else</span>
        {
            pFrameStack[<span class="code-digit">1</span>].pClass=pVirtualClass;
        }

        <span class="code-keyword">int</span> params=GetMethodParametersStackCount(strDesc)+1;
        
        <span class="code-comment">//</span><span class="code-comment">invokestatic - there is no this pointer 
</span>        <span class="code-keyword">if</span>(type==invokestatic) params--;
        <span class="code-comment">//</span><span class="code-comment"> else invokevirtual has this pointer
</span>
        <span class="code-keyword">int</span> nDiscardStack =params;
        <span class="code-keyword">if</span>(pFrameStack[<span class="code-digit">1</span>].pMethod-&gt;access_flags &amp; ACC_NATIVE)
        {
        }
        <span class="code-keyword">else</span> 
        {
            nDiscardStack+=pFrameStack[<span class="code-digit">1</span>].pMethod-&gt;pCode_attr-&gt;max_locals; 
        }
        
        pFrameStack[<span class="code-digit">1</span>].stack = 
        &amp;Frame::pOpStack[pFrameStack-&gt;stack-Frame::pOpStack+pFrameStack[<span class="code-digit">0</span>].sp-params+1];
        pFrameStack[<span class="code-digit">1</span>].sp=nDiscardStack-<span class="code-digit">1</span>;

        <span class="code-keyword">this</span>-&gt;Execute(&amp;pFrameStack[<span class="code-digit">1</span>]);

        <span class="code-comment">//</span><span class="code-comment">if returns then get on stack    
</span>        <span class="code-keyword">if</span>(strDesc.Find(_T(<span class="code-string">"</span><span class="code-string">)V"</span>)) &lt; <span class="code-digit">0</span>)
        {
            nDiscardStack--;        
        }
        <span class="code-comment">//</span><span class="code-comment">Before we return to caller make the stack of caller right
</span>        pFrameStack[<span class="code-digit">0</span>].sp-=nDiscardStack;
    }</pre>

<h4>Invoking native method</h4>

<p>In a java class a method may be marked as native- </p>

<pre>    <span class="code-keyword">public</span> <span class="code-keyword">class</span> Test
    {
        <span class="code-keyword">public</span> native <span class="code-keyword">void</span> Print(string message);
    }</pre>

<p>In byte code <code>ACC_NATIVE</code> is set in the <code>access_flags</code> field of the <code>method_info</code> structure. We decide here like this: </p>

<pre>    <span class="code-keyword">if</span>(pFrame-&gt;pMethod-&gt;access_flags &amp; ACC_NATIVE)
    {
        ExecuteNativeMethod(pFrame);
        <span class="code-keyword">return</span> <span class="code-digit">0</span>;
    }</pre>

<p>Each native method usually has a fixed predefined prototype. Here is the type definitation for our JVM: </p>

<pre>    <span class="code-keyword">typedef</span> Variable (*pNativeMethod)(RuntimeEnvironment* pRuntimeEnvironment);</pre>

<p>Here is how we handle native methods in the JVM: </p>

<pre>    u4 ExecutionEngine::ExecuteNativeMethod(Frame* pFrameStack)
    {
        ASSERT(pFrameStack);
        
        ASSERT(pFrame-&gt;pMethod-&gt;access_flags &amp; ACC_NATIVE);
        Frame* pFrame=&amp;pFrameStack[<span class="code-digit">0</span>];

        JavaClass *pClass = pFrame-&gt;pClass;
        CString strClassName, strMethod, strDesc, strSignature;
        strClassName=pClass-&gt;GetName();
        pClass-&gt;GetStringFromConstPool(
            pFrame-&gt;pMethod-&gt;name_index, strMethod);
        pClass-&gt;GetStringFromConstPool(
            pFrame-&gt;pMethod-&gt;descriptor_index, strDesc);
        DbgPrint(_T(<span class="code-string">"</span><span class="code-string">Execute At Class %s Method %s%s  \n"</span>)
            ,strClassName , strMethod, strDesc);
        strSignature=strClassName+_T(<span class="code-string">"</span><span class="code-string">@"</span>)+strMethod+strDesc;
        pNativeMethod pNativeMethod=GetNativeMethod(strSignature);
        RuntimeEnvironment rte;
        rte.pFrameStack=pFrameStack;
        rte.pClassHeap= pClassHeap;
        rte.pObjectHeap= pObjectHeap;

        <span class="code-keyword">if</span>(pNativeMethod == NULL)
        {
            <span class="code-comment">//</span><span class="code-comment"> what should I do here??
</span>            <span class="code-comment">//</span><span class="code-comment"> System Panic??
</span>            ASSERT(FALSE);
            <span class="code-keyword">return</span> -<span class="code-digit">1</span>;
        }
        <span class="code-keyword">else</span>
        {
            <span class="code-comment">//</span><span class="code-comment">Here we go native
</span>            Variable retVal = pNativeMethod(&amp;rte);

            <span class="code-comment">//</span><span class="code-comment">if returns then get on stack    
</span>            <span class="code-keyword">if</span>(strDesc.Find(_T(<span class="code-string">"</span><span class="code-string">)V"</span>)) &lt; <span class="code-digit">0</span>)
            {
                pFrame-&gt;stack[<span class="code-digit">0</span>]=retVal;
            }
        }
        <span class="code-keyword">return</span> <span class="code-digit">0</span>;
    }</pre>
Here is the implementation of <code>Print</code> method of Test class: 
<pre> 
    <span class="code-comment">//</span><span class="code-comment">Signature: _T("Test@Print(Ljava/lang/String;)V")
</span>     Variable Print(RuntimeEnvironment* pRuntimeEnvironment)
    {
        Variable returnVal;
        Frame *pFrame=&amp;pRuntimeEnvironment-&gt;pFrameStack[<span class="code-digit">0</span>];
        <span class="code-sdkkeyword">Object</span> object=pFrame-&gt;stack[pFrame-&gt;sp].object;
        Variable *pVar
            =pRuntimeEnvironment-&gt;pObjectHeap-&gt;GetObjectPointer(object);
        <span class="code-keyword">if</span>(pVar)
        {
            CString *pString = (CString *)pVar[<span class="code-digit">1</span>].ptrValue;
            <span class="code-keyword">if</span>(pString)    wprintf(_T(<span class="code-string">"</span><span class="code-string">%s"</span>),*pString);
        }

        returnVal.intValue=0;
        <span class="code-keyword">return</span> returnVal;    
    }</pre>

<p>It is the native methods responsibility to correctly operate on stack. The java instruction is here out of scope. Everything is running on real machine here. So, here we pop the string type object reference from stack, convert it to <code>CString</code> object and do our native printing to console. This way we can handle any native operation like creating new window, drawing or do network operation. All these things are done in the implementation of <a href="http://morpheus.kuashaonline.com/">Morpheus</a> project. </p>

<h2>The Garbage Collector</h2>

<p>Java language does not have memory release mechanism. So the JVM must take the responsibility to release memory when some objects are out of scope no longer required or referenced by the application. To do this the JVM may take a number of strategy like reference count, mark and sweep etc. I used mark and sweep method because of its simplicily and accuracy. We start from the stack. We mark each object that is being referenced from the stack references. Then we mark all the objects that is being referenced by the marked objects and so on recursively. After the mark operation we know which objects are connected and which are out of scope. Then we take each object one by one and release its memory from heap. Before that we must call the <code>finalize</code> method of that object to do any cleanup required by the object itself programetically. </p>

<h2>Conclusion</h2>

<p>Thats all about to say for now about how we can implement a simple JVM. The JVM I present here is very limited implementation - though most of the java instructions are supported. It lacks heavily for library and native interface. Please look at the seminar presentation downloadable above for a visual description of JVM and how instructions are executed in a JVM. Full screen view of the presentation is best viewed with spacebar to go to next slide. I am busy with the implementation of <a href="http://morpheus.kuashaonline.com/">Morpheus</a> project at my free time and wish to come with that as well as with a new JVM with a new Window subsystem implementation having Windows Vista and Office 2007 look and feel (ok, ok, thats not technically a big deal but good to have for user interface degign) and oh yes also with a .NET Virtual Execution System with Morpheus for .NET support also. The .NET VES is similar except the complex onfile structure is really painfull when I decode them. All these things I do because I love to do- so I do not try to make a zero bug system. I leave when it seems to work for 'Hello World ++' applications. </p>


						</div>
						

						<div class="float-right" style="margin:20px 0 0 10px;border:1px solid #ccc">
						<div class="msg-300x250" data-format="300x250" data-type="ad" data-publisher="lqm.codeproject.site" data-zone="Languages/C-Cplusplus-Language/General"  data-loadOnView='true'  data-tags='VC6, VC7, VC7.1, VC8.0, C++, C++/CLI, C, Java SE, Virtualization, virtual-machine,rating4.5'><noscript><a href="http://ad.doubleclick.net/N6839/jump/lqm.codeproject.site/Languages/C-Cplusplus-Language/General;sz=300x250;ord=635581648380709040?"><img src="http://ad.doubleclick.net/N6839/ad/lqm.codeproject.site/Languages/C-Cplusplus-Language/General;sz=300x250;ord=635581648380709040?"  width="300px" height="250px" /></a></noscript></div>
						</div>
                        
                        
						
						<h2>License</h2>
						<div id="LicenseTerms"><p>This article, along with any associated source code and files, is licensed under <a href="http://www.opensource.org/licenses/gpl-3.0.html" rel="license">The GNU General Public License (GPLv3)</a></p></div>
						

                        
						<h2>Share</h2>
				        <div style="margin-bottom:40px;width:385px">
					        



<!-- Buttons start here. Copy this ul to your document. -->
<ul class="rrssb-buttons clearfix">
    <li class="email">

        <!-- Replace subject with your message using URL Endocding: http://meyerweb.com/eric/tools/dencoder/ -->
        <a href="mailto:?subject=Home+Made+Java+Virtual+Machine+-+CodeProject&amp;body=http%3a%2f%2fwww.codeproject.com%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">
            <span class="icon">
                <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" width="28px" height="28px" viewBox="0 0 28 28" enable-background="new 0 0 28 28" xml:space="preserve"><g><path d="M20.111 26.147c-2.336 1.051-4.361 1.401-7.125 1.401c-6.462 0-12.146-4.633-12.146-12.265 c0-7.94 5.762-14.833 14.561-14.833c6.853 0 11.8 4.7 11.8 11.252c0 5.684-3.194 9.265-7.399 9.3 c-1.829 0-3.153-0.934-3.347-2.997h-0.077c-1.208 1.986-2.96 2.997-5.023 2.997c-2.532 0-4.361-1.868-4.361-5.062 c0-4.749 3.504-9.071 9.111-9.071c1.713 0 3.7 0.4 4.6 0.973l-1.169 7.203c-0.388 2.298-0.116 3.3 1 3.4 c1.673 0 3.773-2.102 3.773-6.58c0-5.061-3.27-8.994-9.303-8.994c-5.957 0-11.175 4.673-11.175 12.1 c0 6.5 4.2 10.2 10 10.201c1.986 0 4.089-0.43 5.646-1.245L20.111 26.147z M16.646 10.1 c-0.311-0.078-0.701-0.155-1.207-0.155c-2.571 0-4.595 2.53-4.595 5.529c0 1.5 0.7 2.4 1.9 2.4 c1.441 0 2.959-1.828 3.311-4.087L16.646 10.068z"/></g></svg>
            </span>
            <span class="text">email</span>
        </a>
    </li>
    <li class="twitter">
        <!-- Replace href with your Meta and URL information  -->
        <a href="http://twitter.com/home?status=Home+Made+Java+Virtual+Machine+-+CodeProject%20http%3a%2f%2fwww.codeproject.com%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine" class="popup">
            <span class="icon">
                <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
                        width="28px" height="28px" viewBox="0 0 28 28" enable-background="new 0 0 28 28" xml:space="preserve">
                <path d="M24.253,8.756C24.689,17.08,18.297,24.182,9.97,24.62c-3.122,0.162-6.219-0.646-8.861-2.32
                    c2.703,0.179,5.376-0.648,7.508-2.321c-2.072-0.247-3.818-1.661-4.489-3.638c0.801,0.128,1.62,0.076,2.399-0.155
                    C4.045,15.72,2.215,13.6,2.115,11.077c0.688,0.275,1.426,0.407,2.168,0.386c-2.135-1.65-2.729-4.621-1.394-6.965
                    C5.575,7.816,9.54,9.84,13.803,10.071c-0.842-2.739,0.694-5.64,3.434-6.482c2.018-0.623,4.212,0.044,5.546,1.683
                    c1.186-0.213,2.318-0.662,3.329-1.317c-0.385,1.256-1.247,2.312-2.399,2.942c1.048-0.106,2.069-0.394,3.019-0.851
                    C26.275,7.229,25.39,8.196,24.253,8.756z"/>
                </svg>
            </span>
            <span class="text">twitter</span>
        </a>
    </li>

    <li class="facebook">
        <!-- Replace with your URL. For best results, make sure you page has the proper FB Open Graph tags in header: 
        https://developers.facebook.com/docs/opengraph/howtos/maximizing-distribution-media-content/ -->
        <a href="https://www.facebook.com/sharer/sharer.php?u=http%3a%2f%2fwww.codeproject.com%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine" class="popup">
            <span class="icon">
                <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="28px" height="28px" viewBox="0 0 28 28" enable-background="new 0 0 28 28" xml:space="preserve">
                    <path d="M27.825,4.783c0-2.427-2.182-4.608-4.608-4.608H4.783c-2.422,0-4.608,2.182-4.608,4.608v18.434
                        c0,2.427,2.181,4.608,4.608,4.608H14V17.379h-3.379v-4.608H14v-1.795c0-3.089,2.335-5.885,5.192-5.885h3.718v4.608h-3.726
                        c-0.408,0-0.884,0.492-0.884,1.236v1.836h4.609v4.608h-4.609v10.446h4.916c2.422,0,4.608-2.188,4.608-4.608V4.783z"/>
                </svg>
            </span>
            <span class="text">facebook</span>
        </a>
    </li>
    
    <li class="linkedin">
        <!-- Replace href with your meta and URL information -->
        <a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http%3a%2f%2fwww.codeproject.com%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine&amp;title=Home+Made+Java+Virtual+Machine+-+CodeProject" class="popup">
            <span class="icon">
                <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="28px" height="28px" viewBox="0 0 28 28" enable-background="new 0 0 28 28" xml:space="preserve">
                    <path d="M25.424,15.887v8.447h-4.896v-7.882c0-1.979-0.709-3.331-2.48-3.331c-1.354,0-2.158,0.911-2.514,1.803
                        c-0.129,0.315-0.162,0.753-0.162,1.194v8.216h-4.899c0,0,0.066-13.349,0-14.731h4.899v2.088c-0.01,0.016-0.023,0.032-0.033,0.048
                        h0.033V11.69c0.65-1.002,1.812-2.435,4.414-2.435C23.008,9.254,25.424,11.361,25.424,15.887z M5.348,2.501
                        c-1.676,0-2.772,1.092-2.772,2.539c0,1.421,1.066,2.538,2.717,2.546h0.032c1.709,0,2.771-1.132,2.771-2.546
                        C8.054,3.593,7.019,2.501,5.343,2.501H5.348z M2.867,24.334h4.897V9.603H2.867V24.334z"/>
                </svg>
            </span>
            <span class="text">linkedin</span>
        </a>
    </li>
    <li class="reddit">
        <a href="http://www.reddit.com/submit?url=http%3a%2f%2fwww.codeproject.com%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">
            <span class="icon">
                <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" x="0px" y="0px" width="28px" height="28px" viewBox="0 0 28 28" 
                    enable-background="new 0 0 28 28" xml:space="preserve"><g>
                <path d="M11.794 15.316c0-1.029-0.835-1.895-1.866-1.895c-1.03 0-1.893 0.865-1.893 1.895s0.863 1.9 1.9 1.9 C10.958 17.2 11.8 16.3 11.8 15.316z"/>
                <path d="M18.1 13.422c-1.029 0-1.895 0.864-1.895 1.895c0 1 0.9 1.9 1.9 1.865c1.031 0 1.869-0.836 1.869-1.865 C19.969 14.3 19.1 13.4 18.1 13.422z"/>
                <path d="M17.527 19.791c-0.678 0.678-1.826 1.006-3.514 1.006c-0.004 0-0.009 0-0.014 0c-0.004 0-0.01 0-0.015 0 
                c-1.686 0-2.834-0.328-3.51-1.005c-0.264-0.265-0.693-0.265-0.958 0c-0.264 0.265-0.264 0.7 0 1 c0.943 0.9 2.4 1.4 
                4.5 1.402c0.005 0 0 0 0 0c0.005 0 0 0 0 0c2.066 0 3.527-0.459 4.47-1.402 c0.265-0.264 0.265-0.693 0.002-0.958C18.221 
                19.5 17.8 19.5 17.5 19.791z"/><path d="M27.707 13.267c0-1.785-1.453-3.237-3.236-3.237c-0.793 0-1.518 0.287-2.082 
                0.761c-2.039-1.295-4.646-2.069-7.438-2.219 l1.483-4.691l4.062 0.956c0.071 1.4 1.3 2.6 2.7 2.555c1.488 0 2.695-1.208 
                2.695-2.695C25.881 3.2 24.7 2 23.2 2 c-1.059 0-1.979 0.616-2.42 1.508l-4.633-1.091c-0.344-0.081-0.693 0.118-0.803 
                0.455l-1.793 5.7 C10.548 8.6 7.7 9.4 5.6 10.75C5.006 10.3 4.3 10 3.5 10.029c-1.785 0-3.237 1.452-3.237 3.2 c0 1.1 0.6 
                2.1 1.4 2.69c-0.04 0.272-0.061 0.551-0.061 0.831c0 2.3 1.3 4.4 3.7 5.9 c2.299 1.5 5.3 2.3 8.6 2.325c3.228 0 6.271-0.825 
                8.571-2.325c2.387-1.56 3.7-3.66 3.7-5.917 c0-0.26-0.016-0.514-0.051-0.768C27.088 15.5 27.7 14.4 27.7 13.267z M23.186 
                3.355c0.74 0 1.3 0.6 1.3 1.3 c0 0.738-0.6 1.34-1.34 1.34s-1.342-0.602-1.342-1.34C21.844 4 22.4 3.4 23.2 3.355z M1.648 
                13.3 c0-1.038 0.844-1.882 1.882-1.882c0.31 0 0.6 0.1 0.9 0.209c-1.049 0.868-1.813 1.861-2.26 2.9 C1.832 14.2 1.6 13.8 1.6 
                13.267z M21.773 21.57c-2.082 1.357-4.863 2.105-7.831 2.105c-2.967 0-5.747-0.748-7.828-2.105 
                c-1.991-1.301-3.088-3-3.088-4.782c0-1.784 1.097-3.484 3.088-4.784c2.081-1.358 4.861-2.106 7.828-2.106 c2.967 0 5.7 
                0.7 7.8 2.106c1.99 1.3 3.1 3 3.1 4.784C24.859 18.6 23.8 20.3 21.8 21.57z M25.787 14.6 
                c-0.432-1.084-1.191-2.095-2.244-2.977c0.273-0.156 0.59-0.245 0.928-0.245c1.035 0 1.9 0.8 1.9 1.9 
                C26.354 13.8 26.1 14.3 25.8 14.605z"/></g></svg>
            </span>
            <span class="text">reddit</span>
        </a>
    </li>
    <li class="googleplus">
        <!-- Replace href with your meta and URL information.  -->
        <a href="https://plus.google.com/share?url=Check%20out%20Home+Made+Java+Virtual+Machine+-+CodeProject%20http%3a%2f%2fwww.codeproject.com%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine" class="popup">
            <span class="icon">
                <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="28px" height="28px" viewBox="0 0 28 28" enable-background="new 0 0 28 28" xml:space="preserve">
                    <g>
                        <g>
                            <path d="M14.703,15.854l-1.219-0.948c-0.372-0.308-0.88-0.715-0.88-1.459c0-0.748,0.508-1.223,0.95-1.663
                                c1.42-1.119,2.839-2.309,2.839-4.817c0-2.58-1.621-3.937-2.399-4.581h2.097l2.202-1.383h-6.67c-1.83,0-4.467,0.433-6.398,2.027
                                C3.768,4.287,3.059,6.018,3.059,7.576c0,2.634,2.022,5.328,5.604,5.328c0.339,0,0.71-0.033,1.083-0.068
                                c-0.167,0.408-0.336,0.748-0.336,1.324c0,1.04,0.551,1.685,1.011,2.297c-1.524,0.104-4.37,0.273-6.467,1.562
                                c-1.998,1.188-2.605,2.916-2.605,4.137c0,2.512,2.358,4.84,7.289,4.84c5.822,0,8.904-3.223,8.904-6.41
                                c0.008-2.327-1.359-3.489-2.829-4.731H14.703z M10.269,11.951c-2.912,0-4.231-3.765-4.231-6.037c0-0.884,0.168-1.797,0.744-2.511
                                c0.543-0.679,1.489-1.12,2.372-1.12c2.807,0,4.256,3.798,4.256,6.242c0,0.612-0.067,1.694-0.845,2.478
                                c-0.537,0.55-1.438,0.948-2.295,0.951V11.951z M10.302,25.609c-3.621,0-5.957-1.732-5.957-4.142c0-2.408,2.165-3.223,2.911-3.492
                                c1.421-0.479,3.25-0.545,3.555-0.545c0.338,0,0.52,0,0.766,0.034c2.574,1.838,3.706,2.757,3.706,4.479
                                c-0.002,2.073-1.736,3.665-4.982,3.649L10.302,25.609z"/>
                            <polygon points="23.254,11.89 23.254,8.521 21.569,8.521 21.569,11.89 18.202,11.89 18.202,13.604 21.569,13.604 21.569,17.004
                                23.254,17.004 23.254,13.604 26.653,13.604 26.653,11.89      "/>
                        </g>
                    </g>
                </svg>
            </span>
            <span class="text">google+</span>
        </a>
    </li>
    
    <li class="pinterest">
        <!-- Replace href with your meta and URL information.  -->
        <a href="http://pinterest.com/pin/create/button/?url=http%3a%2f%2fwww.codeproject.com%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine&amp;media=http://kurtnoble.com/labs/rrssb/media/facebook-share.jpg&amp;description=Home+Made+Java+Virtual+Machine+-+CodeProject">
            <span class="icon">
                <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="28px" height="28px" viewBox="0 0 28 28" enable-background="new 0 0 28 28" xml:space="preserve">
                <path d="M14.021,1.57C6.96,1.57,1.236,7.293,1.236,14.355c0,7.062,5.724,12.785,12.785,12.785c7.061,0,12.785-5.725,12.785-12.785
                    C26.807,7.294,21.082,1.57,14.021,1.57z M15.261,18.655c-1.161-0.09-1.649-0.666-2.559-1.219c-0.501,2.626-1.113,5.145-2.925,6.458
                    c-0.559-3.971,0.822-6.951,1.462-10.116c-1.093-1.84,0.132-5.545,2.438-4.632c2.837,1.123-2.458,6.842,1.099,7.557
                    c3.711,0.744,5.227-6.439,2.925-8.775c-3.325-3.374-9.678-0.077-8.897,4.754c0.19,1.178,1.408,1.538,0.489,3.168
                    C7.165,15.378,6.53,13.7,6.611,11.462c0.131-3.662,3.291-6.227,6.46-6.582c4.007-0.448,7.771,1.474,8.29,5.239
                    c0.579,4.255-1.816,8.865-6.102,8.533L15.261,18.655z"/>
                </svg>
            </span>
            <span class="text">pinterest</span>
        </a>
    </li>
</ul>
<!-- Buttons end here -->

				        </div> 
    			        


						
						<h2 id="ctl00_AboutHeading">About the Author</h2>
						

<div class="container">
<div style="width:210px;overflow:hidden;float:left;text-align:center">
	<img id="ctl00_AboutAuthorRptr_ctl00_AboutAuthor_memberPhoto" class="profile-pic" src="http://www.codeproject.com/script/Membership/ProfileImages/{fa071df0-d6f3-4e1f-b0a1-2044d69afb94}.jpg" style="border-width:0px;transform:rotate(1deg);" />
</div>
<div class="container-member float-left" style="margin:35px 15px 0 0;">
	<b><a id="ctl00_AboutAuthorRptr_ctl00_AboutAuthor_memberProfileLink" class="author" href="/Members/Maruf-Maniruzzaman">Maruf Maniruzzaman</a></b>
	<div class="company">
		<span id="ctl00_AboutAuthorRptr_ctl00_AboutAuthor_memberJobTitle">Software Developer</span>
		<span id="ctl00_AboutAuthorRptr_ctl00_AboutAuthor_memberCompany">KAZ Software Ltd. Bangladesh.</span> 
		<br /><span id="ctl00_AboutAuthorRptr_ctl00_AboutAuthor_memberLocation">Bangladesh <img src="/script/Geo/Images/BD.gif" alt="Bangladesh" width="16px" height="11px" /></span>
	</div>
</div>
	
<div class="padded-top float-left clearfix">
	Have completed BSc in Computer Science & Engineering from Shah Jalal University of Science & Technology, Sylhet, Bangladesh (<a rel="nofollow" href="http://www.sust.edu">SUST</a>). <br />
&nbsp;<br />
Story books (specially Masud Rana series), tourism, songs and programming is most favorite.<br />
&nbsp;<br />
Blog: <br />
<a rel="nofollow" href="http://www.marufnotes.com">Maruf Notes</a><br />
<a rel="nofollow" href="http://blog.kuashaonline.com">http://blog.kuashaonline.com</a><br />
&nbsp;<br />
Working on small project for 2 factor authentication <a rel="nofollow" href="https://auth2.com">auth2.com</a>

	

	
</div>
</div><br />
						
						

						<div class="clearfix"></div>

						<div style="padding-top:8px">
							
						</div>

						
						<div style="margin:auto;height:90px;margin-top:10px;Widt:730px"> 
							<div class="msg-728x90" data-format="728x90" data-type="ad" data-publisher="lqm.codeproject.site" data-zone="Languages/C-Cplusplus-Language/General"  data-loadOnView='true'  data-tags='VC6, VC7, VC7.1, VC8.0, C++, C++/CLI, C, Java SE, Virtualization, virtual-machine,rating4.5,pos_bottom'><noscript><a href="http://ad.doubleclick.net/N6839/jump/lqm.codeproject.site/Languages/C-Cplusplus-Language/General;sz=728x90;ord=635581648380709040?"><img src="http://ad.doubleclick.net/N6839/ad/lqm.codeproject.site/Languages/C-Cplusplus-Language/General;sz=728x90;ord=635581648380709040?"  width="728px" height="90px" /></a></noscript></div>
						</div>
						
					

				    
					</form>

				</div>

				
				

					<h2>Comments and Discussions</h2>
					<a class="float-left" name="_comments" id="_comments">&nbsp;</a><div id="_MessageBoardctl00_MessageBoard" onclick="return SwitchMessage(event, null)">
<table id="ForumTable" class="forum relaxed" cellpadding="0" cellspacing="0">
<tr>
<td class="header1 callout"><b>You must <a href="https://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine%3ffid%3d1065401">Sign In</a> to use this message board.</b></td>
</tr><tr>
<td><table width="100%" border="0" cellpadding="3px" cellspacing="0">
<tr class="header1">
<td colspan="2" style="white-space:nowrap;"><div class="container">
<div class="float-right">
<form action="/Search.aspx?fid=0" method="get" class="searchbar">
<input type="hidden" name="fid" value="1065401" /><b>Search Comments </b><input type="search" class="search" name="qf" />&nbsp;<input type="submit" value="Go" class="button" />
</form>
</div>
</div></td>
</tr><tr class="header2">
<td></td><td style="width:100%;"><div style="text-align:right;">
<form action="/script/Forums/SetOptions.aspx?floc=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine&amp;fid=1065401" method="get" style="margin:0;padding:0;">
<input type="hidden" name="fid" value="1065401" /><input type="hidden" name="currentQS" value="?floc=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine&amp;fid=1065401" /><input type="hidden" name="floc" value="/Articles/24029/Home-Made-Java-Virtual-Machine" /><input type="checkbox" checked="checked" name="prof" id="prof" style="vertical-align:middle;" /><label for="prof">Profile popups</label>&nbsp;&nbsp;&nbsp;&nbsp;Spacing<select size="1" class="dropdown" name="spc">
<option selected value="Relaxed">Relaxed</option><option value="Compact">Compact</option><option value="Tight">Tight</option>
</select>&nbsp;&nbsp;Noise<select size="1" class="dropdown" name="noise">
<option value="1">Very High</option><option value="2">High</option><option selected value="3">Medium</option><option value="4">Low</option><option value="5">Very Low</option>
</select>&nbsp;&nbsp;Layout<select size="1" class="dropdown" name="view">
<option value="Normal">Normal</option><option value="Topic">Open Topics</option><option selected value="Expanded">Open All</option><option value="Thread">Thread View</option>
</select>&nbsp;&nbsp;Per page<select size="1" class="dropdown" name="mpp">
<option value="10">10</option><option value="25">25</option><option selected value="50">50</option>
</select>&nbsp;&nbsp;&nbsp;<input type="submit" value="Update" name="SetOpt" class="button" />
</form>
</div></td>
</tr>
</table></td>
</tr><tr>
<td><a name="xx0xx"></a><table border="0" cellpadding="2px" cellspacing="0" width="100%">
<tr class="navbar">
<td></td><td style="text-align:right;width:50%;"></td><td style="text-align:right;white-space:nowrap;"><span class="nav-link disabled">First</span> <span class="nav-link disabled">Prev</span> <span class="nav-link disabled">Next</span></td>
</tr>
</table></td>
</tr><tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%" class="fixed-layout blank-background">
<tr>
<td><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" border="0" width="1px" height="5px" alt="" /></td>
</tr><tr id="F4546144_h0" class="header hover-row root">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="20px" class="indent"><a name="xx4546144xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container">Congratulations</td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=10001692">vmateixeira</a></td><td class="date">20-Apr-13  13:41&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content root">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:20px;"><div class="voteform vertical" ownerid="10001692" msgid="4546144" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="20px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2">Excellent work!<br />I imagine that it was not an easy project...<br />&nbsp;<br />Keep up with the good work!<br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=4546144" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/4546144/Congratulations.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF4546144" data-ref="3_4546144" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F4125646_h0" class="header hover-row root">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="20px" class="indent"><a name="xx4125646xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_question.gif" alt="Question" /></td><td class="subject hover-container">Nice Article</td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=171437">Rene Pally</a></td><td class="date">11-Jan-12  11:11&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content root">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:20px;"><div class="voteform vertical" ownerid="171437" msgid="4125646" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="20px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2">Hi Sir,<br />
&nbsp;<br />
Nice article, I would like to know where can I get information about JVM internals? I am developing a personal project.<br />
&nbsp;<br />
Regards<br />
Rene.<br />
<div class="signature">Excellent</div><br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=4125646" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/4125646/Nice-Article.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF4125646" data-ref="3_4125646" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F4210674_h0" class="header hover-row">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="38px" class="indent"><a name="xx4210674xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_answer.gif" alt="Answer" /></td><td class="subject hover-container"><a class="message-link" name="4210674" parent="4125646" thread="4125646" href="/Messages/4210674/Re-Nice-Article.aspx">Re: Nice Article</a></td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=115829">Maruf Maniruzzaman</a></td><td class="date">2-Apr-12  21:12&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:38px;"><div class="voteform vertical" ownerid="115829" msgid="4210674" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="38px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><div class="parent"><a rel="nofollow" onclick="return SwitchMessage(null,4125646);" href="/Messages/4125646/Nice-Article.aspx"><img src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/arrow-up24.png" title="Go to Parent"  style="width:16px;height:16px;border:0" /></a></div>You may search for "The Java Virtual Machine Specification"- I used the second edition- I am not giving the link here because it tends to change a little-<br />
<div class="signature">Maruf Maniruzzaman<br />
<font color="FF0000">@</font> Dhaka, Bangladesh.</div><br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=4125646" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/4210674/Re-Nice-Article.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF4210674" data-ref="3_4210674" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F3865495_h0" class="header hover-row root">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="20px" class="indent"><a name="xx3865495xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container">i'm wonder why do you code this line</td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=7022056">chandufo</a></td><td class="date">22-Apr-11  1:24&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content root">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:20px;"><div class="voteform vertical" ownerid="7022056" msgid="3865495" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="20px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2">hi, <br />
i'm wonder why do you code this line. I dont understand this line in ExecutionEngine File<br />
&nbsp;<br />
pFrameStack[0].sp -= nDiscardStack;<br />
&nbsp;<br />
I think you must replace the code 1 block by code 2 block like following:<br />
Code 1 Block: (your code)<br />
&lt;pre&gt;<br />
	//if returns then get on stack	<br />
	if(strDesc.Find(_T(")V")) &amp;lt; 0)<br />
	{<br />
		nDiscardStack--;		<br />
		//params--;		<br />
	}<br />
&nbsp;<br />
	pFrameStack[0].sp -= nDiscardStack; //??? <br />
	//pFrameStack[0].sp -= params; <br />
	//pFrameStack[0].stack[pFrameStack[0].sp] = pFrameStack[1].stack[pFrameStack[1].sp];<br />
&lt;/pre&gt;<br />
&nbsp;<br />
<br />
code 2 Block: (my code)<br />
&lt;pre&gt;<br />
	//if returns then get on stack	<br />
	if(strDesc.Find(_T(")V")) &amp;lt; 0)<br />
	{<br />
		//nDiscardStack--;		<br />
		params--;		<br />
	}<br />
&nbsp;<br />
	//pFrameStack[0].sp -= nDiscardStack; //??? <br />
	pFrameStack[0].sp -= params; <br />
	pFrameStack[0].stack[pFrameStack[0].sp] = pFrameStack[1].stack[pFrameStack[1].sp];<br />
&lt;/pre&gt;<br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=3865495" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/3865495/im-wonder-why-do-you-code-this-line.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF3865495" data-ref="3_3865495" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F3869587_h0" class="header hover-row">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="38px" class="indent"><a name="xx3869587xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container"><a class="message-link" name="3869587" parent="3865495" thread="3865495" href="/Messages/3869587/Re-im-wonder-why-do-you-code-this-line.aspx">Re: i'm wonder why do you code this line</a></td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=6477245">hoan_micheal</a></td><td class="date">26-Apr-11  16:59&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:38px;"><div class="voteform vertical" ownerid="6477245" msgid="3869587" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="38px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><div class="parent"><a rel="nofollow" onclick="return SwitchMessage(null,3865495);" href="/Messages/3865495/im-wonder-why-do-you-code-this-line.aspx"><img src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/arrow-up24.png" title="Go to Parent"  style="width:16px;height:16px;border:0" /></a></div>do you mean the meaning of this block code? <img src="http://dj9okeyxktdvd.cloudfront.net/script/Forums/Images/smiley_smile.gif" align="top" alt="Smile | :)" /> <br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=3865495" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/3869587/Re-im-wonder-why-do-you-code-this-line.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF3869587" data-ref="3_3869587" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F3976359_h0" class="header hover-row">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="38px" class="indent"><a name="xx3976359xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container"><a class="message-link" name="3976359" parent="3865495" thread="3865495" href="/Messages/3976359/Re-im-wonder-why-do-you-code-this-line.aspx">Re: i'm wonder why do you code this line</a></td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=115829">Maruf Maniruzzaman</a></td><td class="date">29-Jul-11  12:17&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:38px;"><div class="voteform vertical" ownerid="115829" msgid="3976359" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="38px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><div class="parent"><a rel="nofollow" onclick="return SwitchMessage(null,3865495);" href="/Messages/3865495/im-wonder-why-do-you-code-this-line.aspx"><img src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/arrow-up24.png" title="Go to Parent"  style="width:16px;height:16px;border:0" /></a></div>Thank you for your comment-<br />
I wrote this code about 8 years ago- so I do not remember everything I was thinking then-<br />
While it is possible that I did make a mistake here- It was working for my tests and java apps I wrote worked correctly- <br />
&nbsp;<br />
Please let me know if you get wrong result while running java apps- I am sure I wont be able to find time fix the code- but I'll add a note to the article-<br />
&nbsp;<br />
Thanks again for paying attention-<br />
<div class="signature">Maruf Maniruzzaman<br />
<font color="FF0000">@</font> Dhaka, Bangladesh.</div><br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=3865495" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/3976359/Re-im-wonder-why-do-you-code-this-line.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF3976359" data-ref="3_3976359" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F3856060_h0" class="header hover-row root">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="20px" class="indent"><a name="xx3856060xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container">class loader</td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=7839355">Member 7839355</a></td><td class="date">13-Apr-11  18:24&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content root">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:20px;"><div class="voteform vertical" ownerid="7839355" msgid="3856060" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="20px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2">Does this use a classloader like in the JVM specification? If not how/why was this worked around?<br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=3856060" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/3856060/class-loader.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF3856060" data-ref="3_3856060" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F4210670_h0" class="header hover-row">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="38px" class="indent"><a name="xx4210670xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container"><a class="message-link" name="4210670" parent="3856060" thread="3856060" href="/Messages/4210670/Re-class-loader.aspx">Re: class loader</a></td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=115829">Maruf Maniruzzaman</a></td><td class="date">2-Apr-12  21:09&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:38px;"><div class="voteform vertical" ownerid="115829" msgid="4210670" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="38px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><div class="parent"><a rel="nofollow" onclick="return SwitchMessage(null,3856060);" href="/Messages/3856060/class-loader.aspx"><img src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/arrow-up24.png" title="Go to Parent"  style="width:16px;height:16px;border:0" /></a></div>I could not stick to JVM spec entirely all the time for the sake of simplicity- But I used a simple native class loader here (that is not violating spec) that reads the class file directly from disk- Please refer to the article text above-<br />
<div class="signature">Maruf Maniruzzaman<br />
<font color="FF0000">@</font> Dhaka, Bangladesh.</div><br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=3856060" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/4210670/Re-class-loader.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF4210670" data-ref="3_4210670" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F3557732_h0" class="header hover-row root">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="20px" class="indent"><a name="xx3557732xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container">JIT Compiler</td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=115829">Maruf Maniruzzaman</a></td><td class="date">6-Aug-10  12:22&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content root">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:20px;"><div class="voteform vertical" ownerid="115829" msgid="3557732" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="20px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2">If you want to know about jit compilers you may look at my blog- http://blog.kuashaonline.com<br />
<div class="signature">Maruf Maniruzzaman<br />
<font color="FF0000">@</font> Dhaka, Bangladesh.</div><br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=3557732" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/3557732/JIT-Compiler.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF3557732" data-ref="3_3557732" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F3172726_h0" class="header hover-row root">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="20px" class="indent"><a name="xx3172726xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container">This is simple outstanding....</td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-group-16.gif" title="group" alt="group" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=1186309">Md. <b style="color: #FF9900"> M</b>arufuzzaman</a></td><td class="date">25-Aug-09  6:51&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content root">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:20px;"><div class="voteform vertical" ownerid="1186309" msgid="3172726" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="20px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2">I just love CodeProject.com and I have some little contribution over their.. I feel so proud to view your article at codeproject. keep it up...<img src="http://dj9okeyxktdvd.cloudfront.net/script/Forums/Images/thumbs_up.gif" align="top" alt="Thumbs Up | :thumbsup:" />  <img src="http://dj9okeyxktdvd.cloudfront.net/script/Forums/Images/smiley_smile.gif" align="top" alt="Smile | :)" />   <br />
&nbsp;<br />
<div class="ForumSig">I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.<br />
<hr><br />
<u style="color: BLUE">Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.  </u><br />
&nbsp;<br />
Thanks<br />
Md. <b style="color: #FF9900"> M</b>arufuzzaman</hr></div><br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=3172726" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/3172726/This-is-simple-outstanding.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF3172726" data-ref="3_3172726" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F3172732_h0" class="header hover-row">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="38px" class="indent"><a name="xx3172732xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container"><a class="message-link" name="3172732" parent="3172726" thread="3172726" href="/Messages/3172732/Re-This-is-simple-outstanding.aspx">Re: This is simple outstanding....</a></td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-group-16.gif" title="group" alt="group" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=1186309">Md. <b style="color: #FF9900"> M</b>arufuzzaman</a></td><td class="date">25-Aug-09  6:55&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:38px;"><div class="voteform vertical" ownerid="1186309" msgid="3172732" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="38px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><div class="parent"><a rel="nofollow" onclick="return SwitchMessage(null,3172726);" href="/Messages/3172726/This-is-simple-outstanding.aspx"><img src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/arrow-up24.png" title="Go to Parent"  style="width:16px;height:16px;border:0" /></a></div>Oops I forgot to vote,,,, 5 from me;  <br />
&nbsp;<br />
<div class="ForumSig">I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.<br />
<hr><br />
<u style="color: BLUE">Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.  </u><br />
&nbsp;<br />
Thanks<br />
Md. <b style="color: #FF9900"> M</b>arufuzzaman</hr></div><br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=3172726" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/3172732/Re-This-is-simple-outstanding.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF3172732" data-ref="3_3172732" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F3341960_h0" class="header hover-row">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="56px" class="indent"><a name="xx3341960xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container"><a class="message-link" name="3341960" parent="3172732" thread="3172726" href="/Messages/3341960/Re-This-is-simple-outstanding.aspx">Re: This is simple outstanding....</a></td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=115829">Maruf Maniruzzaman</a></td><td class="date">22-Jan-10  21:25&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:56px;"><div class="voteform vertical" ownerid="115829" msgid="3341960" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="56px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><div class="parent"><a rel="nofollow" onclick="return SwitchMessage(null,3172732);" href="/Messages/3172732/Re-This-is-simple-outstanding.aspx"><img src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/arrow-up24.png" title="Go to Parent"  style="width:16px;height:16px;border:0" /></a></div>Thanks You for nice words- <br />
&nbsp;<br />
I had a chance to look at your articles also- I actually track back to your page from munna's page-<br />
We worked together at KAZ Software- <br />
&nbsp;<br />
<div class="signature">Maruf Maniruzzaman<br />
<font color="FF0000">@</font> Dhaka, Bangladesh.</div><br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=3172726" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/3341960/Re-This-is-simple-outstanding.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF3341960" data-ref="3_3341960" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F2555152_h0" class="header hover-row root">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="20px" class="indent"><a name="xx2555152xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container">Impresssed</td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=2642860">Niiiissssshhhhhuuuuu</a></td><td class="date">15-May-08  10:11&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content root">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:20px;"><div class="voteform vertical" ownerid="2642860" msgid="2555152" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="20px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2">nice job.... <img src="http://dj9okeyxktdvd.cloudfront.net/script/Forums/Images/smiley_smile.gif" align="top" alt="Smile | :)" />   <img src="http://dj9okeyxktdvd.cloudfront.net/script/Forums/Images/smiley_smile.gif" align="top" alt="Smile | :)" />  <br />
&nbsp;<br />
<div class="ForumSig">Regards <img src="http://dj9okeyxktdvd.cloudfront.net/script/Forums/Images/rose.gif" align="top" alt="Rose | [Rose]" /> ,<br />
Nishu</div><br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=2555152" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/2555152/Impresssed.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF2555152" data-ref="3_2555152" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F2525078_h0" class="header hover-row root">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="20px" class="indent"><a name="xx2525078xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container">Unhandled exception at 0x0041b833 in kjvm.exe</td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=5073525">alexe100</a></td><td class="date">26-Apr-08  15:38&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content root">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:20px;"><div class="voteform vertical" ownerid="5073525" msgid="2525078" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="20px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2">Hi<br />
&nbsp;<br />
I am a beginner in  java virtual machine implementation and I am trying to implement one JVM in C.<br />
But it is too difficult for me at least till so far.<br />
So I would like to see your JVM running but I cant due to an unhandled exception.<br />
I did these steps:<br />
I download it from  the codeproject site.<br />
I opened it with visual studio 2008 (pro)<br />
I commented the lines:<br />
//#include <zlib.h><br />
//#pragma comment(lib, "zdll.lib")<br />
Because I have no zdll.lib<br />
After generated exe file I write a little class:<br />
&nbsp;<br />
class hello<br />
{<br />
        static void main(String args[])<br />
        {<br />
                System.out.println("Ola Mundo");<br />
        }<br />
}<br />
&nbsp;<br />
then I: javac hello.java<br />
&nbsp;<br />
then:<br />
kjvm.exe hello<br />
&nbsp;<br />
The execution takes about 6 seconds and then a windows xp error dialog box appear. <br />
I push the debug button of the dialog, the visual studio 2008 is opened and VS2008 says:<br />
&nbsp;<br />
Unhandled exception at 0x0041b833 in kjvm.exe: 0xC0000005: Access violation reading location 0xfdfdfe07.<br />
&nbsp;<br />
The line os code is:<br />
&nbsp;<br />
  ...<br />
  pFrameStack[startFrame].pMethod = &pVirtualClass-&gt;methods[mindex];<br />
  pFrameStack[startFrame].stack = Frame::pOpStack;<br />
=&gt;pFrameStack[startFrame].sp = pFrameStack[startFrame].pMethod-&gt;pCode_attr-&gt;max_locals;<br />
  pFrameStack[startFrame].stack[0].object = object;<br />
  ex.Execute(&pFrameStack[startFrame]);<br />
  ...<br />
&nbsp;<br />
<br />
I cant see what is going on. Can you please give me an help<br />
&nbsp;<br />
Many thanks<br />
&nbsp;<br />
Alex </zlib.h><br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=2525078" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/2525078/Unhandled-exception-at-x-b-in-kjvm-exe.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF2525078" data-ref="3_2525078" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F2525172_h0" class="header hover-row">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="38px" class="indent"><a name="xx2525172xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container"><a class="message-link" name="2525172" parent="2525078" thread="2525078" href="/Messages/2525172/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx">Re: Unhandled exception at 0x0041b833 in kjvm.exe</a></td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=115829">Maruf Maniruzzaman</a></td><td class="date">26-Apr-08  18:46&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:38px;"><div class="voteform vertical" ownerid="115829" msgid="2525172" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="38px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><div class="parent"><a rel="nofollow" onclick="return SwitchMessage(null,2525078);" href="/Messages/2525078/Unhandled-exception-at-x-b-in-kjvm-exe.aspx"><img src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/arrow-up24.png" title="Go to Parent"  style="width:16px;height:16px;border:0" /></a></div>Sorry, that java class is very simple still does not work. The System.out classdoes not exists. Adding it is very simple though.<br />
&nbsp;<br />
<pre>
package System;
&nbsp;
<span class="code-keyword">public</span> <span class="code-keyword">class</span> <span class="code-keyword">out</span>
{
   <span class="code-keyword">public</span> native <span class="code-keyword">void</span> println(<span class="code-keyword">string</span> text);
}
&nbsp;
</pre>
&nbsp;<br />
Put it in ./System folder and also add a native method alias for Test.Print native method- 3 lines of code in native method selection switch.<br />
&nbsp;<br />
But my advice is to use just use the classes I have provided with the package. It shows howto print messages. It supports static methods, inheritance etc. I did not add library classes for simplicity. The solution file is setup for debugging. Just open it and try debugging. You'll get how it works.<br />
&nbsp;<br />
Oh. zlib does not require. I added it to use JAR files. But excluded it later for simplicity.<br />
&nbsp;<br />
Thanks for your interest. <br />
&nbsp;<br />
<div class="ForumSig">Maruf Maniruzzaman<br />
Dhaka, Bangladesh.<br />
Homepage: <a href="http://www.kuashaonline.com">http://www.kuashaonline.com</a><br /> [<a href="http://www.kuashaonline.blogspot.com/">Blog</a>] [<a href="http://morpheus.kuashaonline.com">Silverlight Clone</a>] [<a href="http://www.kuashaonline.com/index.htm">Resume</a>]<br />
</div><br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=2525078" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/2525172/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF2525172" data-ref="3_2525172" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F2525290_h0" class="header hover-row">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="56px" class="indent"><a name="xx2525290xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container"><a class="message-link" name="2525290" parent="2525172" thread="2525078" href="/Messages/2525290/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx">Re: Unhandled exception at 0x0041b833 in kjvm.exe</a></td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=5073525">alexe100</a></td><td class="date">26-Apr-08  22:57&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:56px;"><div class="voteform vertical" ownerid="5073525" msgid="2525290" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="56px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><div class="parent"><a rel="nofollow" onclick="return SwitchMessage(null,2525172);" href="/Messages/2525172/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx"><img src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/arrow-up24.png" title="Go to Parent"  style="width:16px;height:16px;border:0" /></a></div>Thank you for your rapid answer.<br />
But I still need help, please.<br />
I do want to experiment the System.out.println capability:<br />
So I created a file named out.java with the code:<br />
&nbsp;<br />
package System;<br />
&nbsp;<br />
public class out<br />
{<br />
   public native void println(string text);<br />
}<br />
&nbsp;<br />
I saved this file on the debug/System directory (debug is where the exe is)<br />
&nbsp;<br />
Then you say ".. also add a native method alias for Test.Print native method- 3 lines of code in native method selection switch."<br />
&nbsp;<br />
Could you be more explicit please? I cant find the Test.Print method.<br />
&nbsp;<br />
Thanks a lot for you time,<br />
&nbsp;<br />
Alex <br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=2525078" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/2525290/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF2525290" data-ref="3_2525290" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F2525302_h0" class="header hover-row">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="74px" class="indent"><a name="xx2525302xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container"><a class="message-link" name="2525302" parent="2525290" thread="2525078" href="/Messages/2525302/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx">Re: Unhandled exception at 0x0041b833 in kjvm.exe</a></td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=115829">Maruf Maniruzzaman</a></td><td class="date">26-Apr-08  23:19&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:74px;"><div class="voteform vertical" ownerid="115829" msgid="2525302" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="74px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><div class="parent"><a rel="nofollow" onclick="return SwitchMessage(null,2525290);" href="/Messages/2525290/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx"><img src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/arrow-up24.png" title="Go to Parent"  style="width:16px;height:16px;border:0" /></a></div>Sure. You have to add following change:<br />
&nbsp;<br />
in ExecutionEngine.cpp at line 788 insert following (just before <code>return NULL;</code>):<br />
&nbsp;<br />
<pre>
<span class="code-keyword">else</span> <span class="code-keyword">if</span>(!strSign.Compare(_T(<span class="code-string">"</span><span class="code-string">System/out@println(Ljava/lang/String;)V"</span>)))
{
	<span class="code-keyword">return</span> Print;
}
</pre>
&nbsp;<br />
Put your 'out.class' file in './lib/System/' folder (see there is a 'lib' folder). The execution path is set in ./lib folder. Please read the article and source code carefully to understand whats going on. Also the PPT may be helpfull.<br />
&nbsp;<br />
I think I should add it to the package. I'll do when I get some free time. I thought it is not required. <br />
&nbsp;<br />
<div class="ForumSig">Maruf Maniruzzaman<br />
Dhaka, Bangladesh.<br />
Homepage: <a href="http://www.kuashaonline.com">http://www.kuashaonline.com</a><br /> [<a href="http://www.kuashaonline.blogspot.com/">Blog</a>] [<a href="http://morpheus.kuashaonline.com">Silverlight Clone</a>] [<a href="http://www.kuashaonline.com/index.htm">Resume</a>]<br />
</div><br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=2525078" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/2525302/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF2525302" data-ref="3_2525302" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F2525378_h0" class="header hover-row">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="92px" class="indent"><a name="xx2525378xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container"><a class="message-link" name="2525378" parent="2525302" thread="2525078" href="/Messages/2525378/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx">Re: Unhandled exception at 0x0041b833 in kjvm.exe</a></td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=5073525">alexe100</a></td><td class="date">27-Apr-08  1:28&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:92px;"><div class="voteform vertical" ownerid="5073525" msgid="2525378" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="92px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><div class="parent"><a rel="nofollow" onclick="return SwitchMessage(null,2525302);" href="/Messages/2525302/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx"><img src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/arrow-up24.png" title="Go to Parent"  style="width:16px;height:16px;border:0" /></a></div>The method must be static because it is called in the static main() mathod and I dont know <br />
how to define a static method on the GetNativeMethod() method.<br />
Please, lets forget this example.<br />
&nbsp;<br />
On the downloaded zip file there is no example java file with a main. <br />
So, I write this one using the classes provided:<br />
&nbsp;<br />
class hello<br />
{<br />
        static void main(String args[])<br />
        {<br />
                //Syste.ou.pintln("Ola Mundo"); //This must be static to compile.<br />
		String x=new String(); //This is the String class provided<br />
		String y=x.toString();<br />
        }<br />
}<br />
&nbsp;<br />
Then I compile it: (I am in the kjvm\debug directory)<br />
c:\&gt;javac -classpath ../kjvm/lib/ hello.java<br />
&nbsp;<br />
It compiles weel.<br />
&nbsp;<br />
Then I run:<br />
kjvm.exe hello<br />
&nbsp;<br />
and an unhandled exception occurs again. <img src="http://dj9okeyxktdvd.cloudfront.net/script/Forums/Images/smiley_frown.gif" align="top" alt="Frown | :-(" /> <br />
&nbsp;<br />
The problem is on the "int mindex" variable that is filled with -1. It seems that there is no Entry method<br />
&nbsp;<br />
...<br />
Object object=oheap.CreateObject(pClass1);<br />
JavaClass *pVirtualClass=pClass1;<br />
int mindex=pClass1-&gt;GetMethodIndex(_T("Entry"),_T("()I"),pVirtualClass);<br />
pFrameStack[startFrame].pClass = pVirtualClass;	<br />
...<br />
&nbsp;<br />
<br />
&nbsp;<br />
<br />
Please, if this app is not well, please could you provide me an example application for for the kjvm.<br />
&nbsp;<br />
My email is alex100@iol.pt<br />
&nbsp;<br />
Many thanks<br />
&nbsp;<br />
Alex <br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=2525078" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/2525378/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF2525378" data-ref="3_2525378" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F2525400_h0" class="header hover-row">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="110px" class="indent"><a name="xx2525400xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container"><a class="message-link" name="2525400" parent="2525378" thread="2525078" href="/Messages/2525400/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx">Re: Unhandled exception at 0x0041b833 in kjvm.exe</a></td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=115829">Maruf Maniruzzaman</a></td><td class="date">27-Apr-08  1:50&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:110px;"><div class="voteform vertical" ownerid="115829" msgid="2525400" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="110px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><div class="parent"><a rel="nofollow" onclick="return SwitchMessage(null,2525378);" href="/Messages/2525378/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx"><img src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/arrow-up24.png" title="Go to Parent"  style="width:16px;height:16px;border:0" /></a></div>Plesase set following in project property pages Debugging-<br />
&nbsp;<br />
Command Arguments: JavaTest<br />
Working Directory: $(ProjectDir)/lib<br />
&nbsp;<br />
And run. In my case it works. I thought it was set in project file. But I forgot to set those. Also please make sure the lib folder with files are in place as it was when you downloaded the zip file.<br />
&nbsp;<br />
Oh, also I did not use main as entry method. I used Entry. And it does not need to be static. Its a violation - but who cares for such an experimental project.<br />
&nbsp;<br />
JavaTest.java in lib folder is an example application that runs. It uses Test as super class and Print method is defined in Test.java.<br />
&nbsp;<br />
Please let me know if you face any other difficulties. <br />
&nbsp;<br />
<div class="ForumSig">Maruf Maniruzzaman<br />
Dhaka, Bangladesh.<br />
Homepage: <a href="http://www.kuashaonline.com">http://www.kuashaonline.com</a><br /> [<a href="http://www.kuashaonline.blogspot.com/">Blog</a>] [<a href="http://morpheus.kuashaonline.com">Silverlight Clone</a>] [<a href="http://www.kuashaonline.com/index.htm">Resume</a>]<br />
</div><br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=2525078" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/2525400/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF2525400" data-ref="3_2525400" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F2525418_h0" class="header hover-row">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="120px" class="indent"><a name="xx2525418xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container"><a class="message-link" name="2525418" parent="2525400" thread="2525078" href="/Messages/2525418/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx">Re: Unhandled exception at 0x0041b833 in kjvm.exe</a></td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=5073525">alexe100</a></td><td class="date">27-Apr-08  2:20&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:120px;"><div class="voteform vertical" ownerid="5073525" msgid="2525418" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="120px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><div class="parent"><a rel="nofollow" onclick="return SwitchMessage(null,2525400);" href="/Messages/2525400/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx"><img src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/arrow-up24.png" title="Go to Parent"  style="width:16px;height:16px;border:0" /></a></div>Ok, it works now. On command prompt kjvm.exe must be in ./lib directory. I didnt knew that till you tell me <img src="http://dj9okeyxktdvd.cloudfront.net/script/Forums/Images/smiley_smile.gif" align="top" alt="Smile | :)" /> <br />
Ok, it is ok now.<br />
I will try to modify it in order to call the main method and then I want to convert it to C.<br />
&nbsp;<br />
Thank you very much for your attention to me.<br />
&nbsp;<br />
Alex <br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=2525078" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/2525418/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF2525418" data-ref="3_2525418" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F2525434_h0" class="header hover-row">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="130px" class="indent"><a name="xx2525434xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container"><a class="message-link" name="2525434" parent="2525418" thread="2525078" href="/Messages/2525434/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx">Re: Unhandled exception at 0x0041b833 in kjvm.exe</a></td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=115829">Maruf Maniruzzaman</a></td><td class="date">27-Apr-08  2:36&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:130px;"><div class="voteform vertical" ownerid="115829" msgid="2525434" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="130px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><div class="parent"><a rel="nofollow" onclick="return SwitchMessage(null,2525418);" href="/Messages/2525418/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx"><img src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/arrow-up24.png" title="Go to Parent"  style="width:16px;height:16px;border:0" /></a></div>Its my pleasure that you tried my application. This is a very simple JVM implementation. I just stopped when it started to work for sample apps in lib directory. I was in time pressure- I had to do this in one semester for a research lab course. In Morpheus project (see article) I have implemented lot of extra features- fixed memory leaks, added a good garbase collector etc. I am hoping to come with that also soon. <br />
&nbsp;<br />
<div class="ForumSig">Maruf Maniruzzaman<br />
Dhaka, Bangladesh.<br />
Homepage: <a href="http://www.kuashaonline.com">http://www.kuashaonline.com</a><br /> [<a href="http://www.kuashaonline.blogspot.com/">Blog</a>] [<a href="http://morpheus.kuashaonline.com">Silverlight Clone</a>] [<a href="http://www.kuashaonline.com/index.htm">Resume</a>]<br />
</div><br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=2525078" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/2525434/Re-Unhandled-exception-at-x-b-in-kjvm-exe.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF2525434" data-ref="3_2525434" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F2513136_h0" class="header hover-row root">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="20px" class="indent"><a name="xx2513136xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container">Really nice</td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=3212027">kbsbng</a></td><td class="date">18-Apr-08  2:27&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content root">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:20px;"><div class="voteform vertical" ownerid="3212027" msgid="2513136" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="20px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2">That's really nice...  <img src="http://dj9okeyxktdvd.cloudfront.net/script/Forums/Images/smiley_smile.gif" align="top" alt="Smile | :)" />  <br />
&nbsp;<br />
<div class="ForumSig">Regards,<br />
Keshavaprasad B S<br />
Homepage: <a href="http://kbsbng.googlepages.com">http://kbsbng.googlepages.com</a></div><br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=2513136" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/2513136/Really-nice.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF2513136" data-ref="3_2513136" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F2512135_h0" class="header hover-row root">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="20px" class="indent"><a name="xx2512135xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container">Good job</td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=2684355">
  <font color="#0730FF">Dr.Luiji</font>
</a></td><td class="date">17-Apr-08  10:38&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content root">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:20px;"><div class="voteform vertical" ownerid="2684355" msgid="2512135" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="20px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2">Very interesting article, thanks for sharing that. <br />
&nbsp;<br />
<div class="ForumSig"><font color="#0730FF">Dr.Luiji</font><br />
&nbsp;<br />
<b>Trust and you'll be trusted.</b><br />
</div><br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=2512135" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/2512135/Good-job.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF2512135" data-ref="3_2512135" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F2507412_h0" class="header hover-row root">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="20px" class="indent"><a name="xx2507412xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container">Nice!</td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=976089">
  <font color="#3399ff">
    <b>ThatsAlok</b>
</a></td><td class="date">14-Apr-08  20:36&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content root">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:20px;"><div class="voteform vertical" ownerid="976089" msgid="2507412" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="20px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2">Nice implementation buddy!, after very long time I encountered quite a good piece of code/concept <img src="http://dj9okeyxktdvd.cloudfront.net/script/Forums/Images/smiley_smile.gif" align="top" alt="Smile | :)" />  <br />
&nbsp;<br />
<div class="ForumSig">  <p align="right"> <small>"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow</small><br /><small>Never mind - my own stupidity is the source of every "problem" - Mixture  </small></p>
cheers, <br />
<a href="http://visualcpp.org"> Alok Gupta </a> <br />
VC Forum Q&A :- <a href="http://tinyurl.com/2o85lq">I</a>/<a href="http://tinyurl.com/38p8nj">IV</a><br />
<b>Support <a href="http://cry.org">CRY- Child Relief and You</a>/codeProject$$&gt;</b></div><br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=2507412" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/2507412/Nice.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF2507412" data-ref="3_2507412" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F2476601_h0" class="header hover-row root">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="20px" class="indent"><a name="xx2476601xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container">excellent explanation</td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=1637224">nhm tanveer hossain khan (hasan)</a></td><td class="date">22-Mar-08  1:38&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content root">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:20px;"><div class="voteform vertical" ownerid="1637224" msgid="2476601" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="20px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2">it would be very nice if you can contribute on openjdk project, at least port jdk for mac osx.   <img src="http://dj9okeyxktdvd.cloudfront.net/script/Forums/Images/smiley_smile.gif" align="top" alt="Smile | :)" />  <br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=2476601" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/2476601/excellent-explanation.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF2476601" data-ref="3_2476601" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F2476650_h0" class="header hover-row">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="38px" class="indent"><a name="xx2476650xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container"><a class="message-link" name="2476650" parent="2476601" thread="2476601" href="/Messages/2476650/Re-excellent-explanation.aspx">Re: excellent explanation</a></td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=115829">Maruf Maniruzzaman</a></td><td class="date">22-Mar-08  3:12&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:38px;"><div class="voteform vertical" ownerid="115829" msgid="2476650" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="38px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><div class="parent"><a rel="nofollow" onclick="return SwitchMessage(null,2476601);" href="/Messages/2476601/excellent-explanation.aspx"><img src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/arrow-up24.png" title="Go to Parent"  style="width:16px;height:16px;border:0" /></a></div>I am not sure if I can contribute. I do not get much time for development as my own. I do a full time job that is 48 hours a week already. The amout of spare time I get for programming I try to spend that on challenging but small projects. Anyway I'll try to get some timeto work on open source projects- thanks for your sugestion. <br />
&nbsp;<br />
<div class="ForumSig">Maruf Maniruzzaman<br />
Dhaka, Bangladesh.<br />
Homepage: <a href="http://www.kuashaonline.com">http://www.kuashaonline.com</a><br /> [<a href="http://www.kuashaonline.blogspot.com/">Blog</a>] [<a href="http://morpheus.kuashaonline.com">Silverlight Clone</a>] [<a href="http://www.kuashaonline.com/index.htm">Resume</a>]<br />
</div><br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=2476601" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/2476650/Re-excellent-explanation.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF2476650" data-ref="3_2476650" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F2451408_h0" class="header hover-row root">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="20px" class="indent"><a name="xx2451408xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container">it doesn't build for me under VS 2005</td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=3238241">PaulTopping</a></td><td class="date">4-Mar-08  7:33&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content root">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:20px;"><div class="voteform vertical" ownerid="3238241" msgid="2451408" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="20px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2">Judging by the name of the solution file, kjvm.vc800.sln, it was intended to be built in version 8 of MS Visual C++ which is also known as Visual Studio 2005. However, I get lots of errors. The structure Frame is used extensively but seems not to be defined. <br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=2451408" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/2451408/it-doesnt-build-for-me-under-VS.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF2451408" data-ref="3_2451408" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr id="F2451997_h0" class="header hover-row">
<td class="subject-line expanded " width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="38px" class="indent"><a name="xx2451997xx"></a><img height="16px" width="16px" align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" alt="General" /></td><td class="subject hover-container"><a class="message-link" name="2451997" parent="2451408" thread="2451408" href="/Messages/2451997/Re-it-doesnt-build-for-me-under-VS.aspx">Re: it doesn't build for me under VS 2005</a></td><td class="icon"><img border="0" src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/icn-member-16.gif" title="member" alt="member" height="16px" /></td><td class="author"><a href="/script/Membership/View.aspx?mid=115829">Maruf Maniruzzaman</a></td><td class="date">4-Mar-08  17:41&nbsp;</td>
</tr>
</table></td>
</tr><tr class="content">
<td class="expanded" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr valign="top">
<td class="indent align-right" style="width:38px;"><div class="voteform vertical" ownerid="115829" msgid="2451997" votingType="GoodOrBad">

</div><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" height="1px" width="38px" alt="" /></td><td class="text"><table border="0" cellpadding="0" cellspacing="5px" width="100%">
<tr>
<td><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td colspan="2"><div class="parent"><a rel="nofollow" onclick="return SwitchMessage(null,2451408);" href="/Messages/2451408/it-doesnt-build-for-me-under-VS.aspx"><img src="//dj9okeyxktdvd.cloudfront.net/App_Themes/CodeProject/Img/arrow-up24.png" title="Go to Parent"  style="width:16px;height:16px;border:0" /></a></div>I have uploaded a new copy. It can be used directly with Visual Studio 2008 and if you want to use previous version (VS 6 is also OK) just create a new empty project and add all cpp, rc, h files to your ptoject. It should work witout any problem.I developed it with VS 6. But right now I do not have that version. Thank you. <br />
&nbsp;<br />
<div class="ForumSig">Maruf Maniruzzaman<br />
Dhaka, Bangladesh.<br />
Homepage: <a href="http://www.kuashaonline.com">http://www.kuashaonline.com</a><br /><br />
<a href="http://www.kuashaonline.blogspot.com/">Blog you should not miss</a><br />
&nbsp;<br />
Tomorrow is a blank page</div>
<div class="ForumMod">modified on Saturday, March 8, 2008 5:27 AM</div><br /></td>
</tr><tr class="footer" style="vertical-align:top;">
<td><a href="http://www.codeproject.com/script/Membership/LogOn.aspx?rp=%2fArticles%2f24029%2fHome-Made-Java-Virtual-Machine">Sign In</a>·<wbr><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;tid=2451408" title="View&nbsp;Thread">View&nbsp;Thread</a>·<wbr><a href="/Messages/2451997/Re-it-doesnt-build-for-me-under-VS.aspx" title="Get permanent link">Permalink</a></td><td style="text-align:right;"><span id="MVF2451997" data-ref="3_2451997" class="rating-label" style="white-space:nowrap;"></span></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table></td>
</tr><tr>
<td><img src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/t.gif" border="0" width="1px" height="5px" alt="" /></td>
</tr><tr>
<td><table width="100%" cellpadding="2px" cellspacing="0">
<tr class="footer">
<td>Last Visit: 31-Dec-99  19:00 &nbsp; &nbsp; Last Update: 29-Jan-15  11:47</td><td><a href="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401">Refresh</a></td><td style="text-align:right;white-space:nowrap;"><input id="_mbnUrl" type="hidden" value="/Articles/24029/Home-Made-Java-Virtual-Machine?fid=1065401&amp;fr=29" /><span class="nav-link selected">1</span></td>
</tr>
</table></td>
</tr>
</table>
</div><p class="small-text"><img align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_general.gif" width="16px" height="16px" alt="General" /> General &nbsp;&nbsp; <img align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_news.gif" width="16px" height="16px" alt="News" /> News &nbsp;&nbsp; <img align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_idea.gif" width="16px" height="16px" alt="Suggestion" /> Suggestion &nbsp;&nbsp; <img align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_question.gif" width="16px" height="16px" alt="Question" /> Question &nbsp;&nbsp; <img align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_bug.gif" width="16px" height="16px" alt="Bug" /> Bug &nbsp;&nbsp; <img align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_answer.gif" width="16px" height="16px" alt="Answer" /> Answer &nbsp;&nbsp; <img align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_joke.gif" width="16px" height="16px" alt="Joke" /> Joke &nbsp;&nbsp; <img align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_rant.gif" width="16px" height="16px" alt="Rant" /> Rant &nbsp;&nbsp; <img align="top" src="//dj9okeyxktdvd.cloudfront.net/script/Forums/Images/msg_admin.gif" width="16px" height="16px" alt="Admin" /> Admin &nbsp;&nbsp; </p>
				

			</div>
			
		</td>
		<td width="170px">
			<div id="ctl00_RightSideBar" class="container-article-info">

    			

<div class="header">Info</div>
<div class="article-summary">

<a id="ctl00_InfoBox_ParentLink"></a>

<table cellpadding="0" cellspacing="0" class="article-info">

    <ul class="prize-list">
<li>Best C++/MFC article of March 2008 </li>
</ul>

    
	

	
	

	

	

	

	<tr><td>First Posted&nbsp;</td><td nowrap="nowrap" class="value"><span itemprop="datePublished" content="2008-03-02">1 Mar 2008</span></td></tr>

	<tr><td>Views&nbsp;</td><td class="value">107,989</td></tr>

	
	<tr><td>Downloads&nbsp;</td><td  class="value">3,652</td></tr>
		

	
	<tr><td>Bookmarked&nbsp;</td><td class="value">101 times</td></tr>
	

	

	

    

	<tr><td colspan="2"></td></tr>
	
	
</table>
</div>

                <div id="RHSticky" class="container-article-info-sticky">
				    

                    
                    <div class="padded-top">
                        
                    </div>

				    <div style="width:160px;margin: 10px auto;">
					    <div class="msg-160x600" data-format="160x600" data-type="ad" data-publisher="lqm.codeproject.site" data-zone="Languages/C-Cplusplus-Language/General"  data-tags='VC6, VC7, VC7.1, VC8.0, C++, C++/CLI, C, Java SE, Virtualization, virtual-machine,rating4.5'><noscript><a href="http://ad.doubleclick.net/N6839/jump/lqm.codeproject.site/Languages/C-Cplusplus-Language/General;sz=160x600;ord=635581648427977123?"><img src="http://ad.doubleclick.net/N6839/ad/lqm.codeproject.site/Languages/C-Cplusplus-Language/General;sz=160x600;ord=635581648427977123?"  width="160px" height="600px" /></a></noscript></div>
				    </div>

				    

				    

				    
				</div>

			</div>
		</td>
		</tr></table>

		
		<div class="theme1-background" style="height:2px" id="stickyStop"></div>

		<div class="extended tiny-text">
			<div class="row">
				<div class="float-left">
					<a id="ctl00_PermaLink" itemprop="url" href="/Articles/24029/Home-Made-Java-Virtual-Machine">Permalink</a> | 
					<a id="ctl00_AdvertiseLink" href="http://developermedia.com/">Advertise </a> |
					<a id="ctl00_PrivacyLink" href="/info/privacy.aspx">Privacy</a> |
                    <a id="ctl00_TermsOfUseLink" href="/info/TermsOfUse.aspx">Terms of Use</a> |
					<a id="ctl00_Mobile" rel="nofollow" href="/Articles/24029/Home-Made-Java-Virtual-Machine?display=Mobile">Mobile</a>
					<br />
								
					
					Web02 |
					2.8.150129.1 |
					Last Updated 17 Mar 2008								
				</div>

                <div id="ctl00_GoogleTranslate" class="translate float-left"></div>      

				<div class="float-right align-right">
					Article Copyright 2008 by Maruf Maniruzzaman<br />Everything else
					Copyright &copy; <a href="mailto:webmaster@codeproject.com">CodeProject</a>, 1999-2015 <br />
				</div>

				


<div class="page-width">
Layout: <a id="ctl00_PageWidth_FixedT" title="Fixed width layout" rel="nofollow" class=" active" href="/Articles/24029/Home-Made-Java-Virtual-Machine?PageFlow=FixedWidth">fixed</a>
|
<a id="ctl00_PageWidth_FluidT" title="Fluid layout" rel="nofollow" href="/Articles/24029/Home-Made-Java-Virtual-Machine?PageFlow=Fluid">fluid</a>
</div>



			</div>
		</div>
		

		<br clear="all" />
		
			

	</div> 
	</div>
</div>


<div style="display:none;" id="dm_AdTable">
	
</div>
<img id="ctl00_Audience" src="http://pubads.g.doubleclick.net/activity;dc_iu=/6839/DFPAudiencePixel;ord=&#39;635581648376341032&#39;;dc_seg=33705250?" style="border-width:0px;height:1px;width:1px;" />



<script type="text/javascript" language="Javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script><script type='text/javascript'>//<![CDATA[
if (typeof jQuery == 'undefined') {
    document.write(unescape("%3Cscript src='/script/JS/jquery-1.6.2.min.js' type='text/javascript' %3E%3C/script%3E"));
}//]]></script>
<script type="text/javascript" language="Javascript" src="//dj9okeyxktdvd.cloudfront.net/script/Articles/JS/article.js?dt=2.8.150129.1"></script>
<script type="text/javascript" language="Javascript" src="//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
<script type="text/javascript" language="Javascript" src="//dj9okeyxktdvd.cloudfront.net/script/JS/navbar.js?dt=2.8.150129.1"></script>
<script type="text/javascript" language="Javascript" src="//dj9okeyxktdvd.cloudfront.net/script/Membership/JS/Notifications.js?dt=2.8.150129.1"></script>
<script type="text/javascript" language="Javascript" src="/Script/Membership/JS/MemberProfilePopup.js?v=1.3"></script>
<script type="text/javascript" language="Javascript">//<![CDATA[
function googleTranslateElementInit() {  new google.translate.TranslateElement({   pageLanguage: 'en',   layout: google.translate.TranslateElement.InlineLayout.SIMPLE,   autoDisplay: false,   gaTrack: true,   gaId: 'UA-1735123-1'},  'ctl00_GoogleTranslate');}
$(document).ready(function() { anchorAnimate();
$('#RHSticky').sticky($('#stickyStop'));
$('#ctl00_Nav').sticky($('#stickyStop'));
});
$(function() {
                                            var $downloads =  $('ul.download');
                                            $downloads.addClass('float-left')
                                                        .wrap('<div class="row"></div>');
                                            $downloads.after('<div class="float-left" style="margin-top:25px;margin-left:30px"><div data-format="1x11" data-type="ad" data-publisher="lqm.codeproject.site" data-zone="downloadlink" data-tags="vc6%2cvc7%2cvc7.1%2cvc8.0%2cc%2b%2b%2cc%2b%2b%2fcli%2cc%2cjava+se%2cvirtualization%2cvirtual-machine"></div></div>');
                                    });
$(function ()
                {
                    $('.oauth').click(function () {
                        $this = $(this);
                        href = $this.attr('href');
                        var myWindow = window.open(href, 'popup',
                                    'width=800,height=600,location=0,menubar=0,resizeable=0,scrollbars=0,toolbar=0');
                        myWindow.focus();
                        var timer = setInterval(function () {
                                        if (myWindow.closed) {
                                            clearInterval(timer);
                                            // window.location.reload(); // May do a POST reload, shows a warning
                                            window.location = window.location; // force a GET reload
                                        }
                                    }, 200);
                        return false;
                    });
                });
var oSrchFlt = false, oSrchBox=false,srchBoxFoc=false;
$(document).ready(function() {
 if(InitWatermark)InitWatermark('sb_tb', 'Search for articles, questions, tips');
 var sbar = $('#sb_tb'); 
 var sfilter = $('#SearchFilter');
 if (sbar && sfilter) {
  sfilter.removeClass('popup'); sfilter.hide(); sfilter.removeClass('open');
  sbar.blur(function() {
 if (!oSrchFlt) {sfilter.hide(); sfilter.removeClass('open');}
 srchBoxFoc=false;
 });
  sbar.focus(function() {
 oSrchFlt=false; srchBoxFoc=true;
 sfilter.show(); sfilter.addClass('open');
 });
  sbar.mouseleave(function() { oSrchBox=false; });
  sbar.mouseover(function() { oSrchBox=true; });
  sfilter.mouseleave(function() { oSrchFlt=false; if (!srchBoxFoc&&!oSrchBox) { sfilter.hide(); sfilter.removeClass('open'); }});
  sfilter.mouseover(function() { oSrchFlt=true; });
 }
});
$('#clear-rate_ctl00_RateArticle_RSU').click(function () {    $('#ctl00_RateArticle_RSU').hide(); return false;});$("#ctl00_RateArticle_RateItemWrapper")   .removeClass("container-rating")   .hover( function() { $('#ctl00_RateArticle_RSU').fadeIn('fast'); },            function() { $('#ctl00_RateArticle_RSU').fadeOut('fast'); } );
function PostBack_ctl00_RateArticle_RateItemWrapper() {
  return rateItem(24029,2,1,true,true,3,'LargeStars');
}

                        function getVotesHistogram(objectId, objectTypeId, containerId, loadingId) {
                            if (!$('#' + containerId).attr('alreadyRequested')){
                                $.ajax({
                                    url: '/script/Ratings/Ajax/Histogram.aspx?obid=' + objectId + '&obtid='+objectTypeId,
                                    success: function (data) {
                                        $('#' + containerId).html(data);
                                        $('#' + loadingId).hide();
                                    }
                                });
                                $('#' + containerId).attr('alreadyRequested', 'true');
                            }
                        }
$(document).ready(function() {   new starRating('#ctl00_RateArticle_VoteFormDiv', PostBack_ctl00_RateArticle_RateItemWrapper,'ctl00_RateArticle');
  $('#ctl00_RateArticle_RB').mouseenter(function() {     getVotesHistogram(24029,2   ,'ctl00_RateArticle_Histogram','ctl00_RateArticle_Loading');  })})
$(document).ready(function() { $('#ctl00_RateArticle_SubmitRateBtn').hide(); });
$(document).ready(function() { $('#ctl00_RateArticle_SubmitRateBtn').hide(); });function ChkRtctl00_RateArticle(){}

forumDir = '/script/Forums/';
staticServer = '//dj9okeyxktdvd.cloudfront.net';
allowReporting = false;
allowRating = false;
allowRatingDisplay = true;
var smoothScroll = true;
Selected        = -1;
oldTitle        = document.title;
minMessageScore = 1;
minMessageScore = 5;
abuseScore      = -2;
spamScore       = -1;
getRatingUrl    = '/script/Ratings/Ajax/GetRatings.aspx';
noiseThreshold  = 3;
getRatingRefKey = 'obrs';


//]]>
</script>


</body>
</html>